【问题标题】:Listbox Binding With No Results Listed未列出任何结果的列表框绑定
【发布时间】:2015-05-05 00:40:23
【问题描述】:

我有一个 Windows Phone 应用程序,我正在尝试将 ObservableCollection 绑定到一个列表框,以便在此刻列出字符串。但是,当我运行应用程序时,没有列出任何内容,而且我看不到哪里出错了。

XAML:

                <ListBox ItemsSource="{Binding EventList}">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding}" Foreground="Black" FontSize="20"/>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>

代码隐藏:

    private ObservableCollection<String> eventList = new ObservableCollection<String>();

    public ObservableCollection<String> EventList
    {
        get { return eventList; }
    }

    public MainPage()
    {
        eventList.Add("Event One");
        eventList.Add("Event Two");
        eventList.Add("Event Three");

        this.InitializeComponent();

        this.NavigationCacheMode = NavigationCacheMode.Required;
    }

【问题讨论】:

    标签: xaml binding listbox windows-phone


    【解决方案1】:

    您是否将主页的 DataContext 设置为具有 EventList 作为属性的应用程序类?在你的 get 访问器上设置一个断点并检查它是否被调用。如果没有,则需要设置DataContext。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-05-27
      • 1970-01-01
      • 2019-06-30
      • 2015-04-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多