【问题标题】:WP7 : Populating a ListBox depending on the input from another ListBoxWP7:根据来自另一个 ListBox 的输入填充 ListBox
【发布时间】:2012-10-11 02:39:17
【问题描述】:

我正在尝试根据另一个 ListBox (ListBox1) 的 selectedItem 将 ListItems 添加到 ListBox (ListBox3)。问题是,项目没有添加到列表框中。

代码如下:

      private void createlist()
      {
        if (listBox1.SelectedValue.ToString().Equals("EPL"))

        {
            ListBoxItem manchesterunited = new ListBoxItem();
            manchesterunited.Content = "Manchester United";
            listBox3.Items.Add(manchesterunited);
        }
     }

    private void listBox1_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
    {
        createlist();
    }

createlist() 进行更改并在 ListBox1 的 SelctionChanged() 事件中调用。

C# 和 WP7 编程新手,我们将不胜感激。

【问题讨论】:

    标签: windows-phone-7 listbox listboxitem listboxitems


    【解决方案1】:

    在您的viewmodel 中创建列表并将listbox 绑定到您的视图模型中的list<>,例如SelectedList。当用户从ListBox1 中选择项目时,只需使用适当的列表和Notify the property changed event 更改 SelectedList 的值。它会完成的。!

    【讨论】:

      【解决方案2】:

      我认为你的程序没有在 mvvm 结构中运行。

      确保你的逻辑是正确的。您可以在该行设置断点
      ListBoxItem manchesterunited = new ListBoxItem(); 确保在 if 代码块中运行这些代码。

      在列表框中添加控件的方式是正确的。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-01-21
        • 1970-01-01
        • 2018-03-08
        • 1970-01-01
        • 1970-01-01
        • 2017-01-13
        相关资源
        最近更新 更多