【问题标题】:My databinding fails, is the path wrong?我的数据绑定失败,路径错误吗?
【发布时间】:2013-07-18 21:41:16
【问题描述】:

我正在尝试创建一个简单的 RSS 新闻聚合器。但是我在绑定上做错了。

xaml:

<phone:LongListSelector 
       x:Name="MainLongListSelector" 
       Margin="0,0,-12,0" 
       ItemsSource="{Binding Path=News.List}"     
       SelectionChanged="MainLongListSelector_SelectionChanged">

背后的代码:

   (mainpage)
    public MainPage()
    {
        InitializeComponent();

        // Set the data context of the LongListSelector control 
        // to the sample data
        DataContext = App.ViewModel;


   (viewmodel)
   public class NewsViewModel : BaseViewModel
   {
        public NewsRepository News { get; private set; }
   }

NewsRepository 只是一个持有List&lt;obj&gt; List 的模型对象。谁能给我指出事情横向发展的方向?

应用程序运行良好,但我手动输入的列表中的单个项目没有显示在应用程序中:-(

我已经在将DataContext 分配给那里的视图模型内容时设置了断点...

【问题讨论】:

  • 没有更多代码很难说。显示您的 longlistselector 项目模板、News.List 和 News.List 对象内的对象定义。
  • 同意@AlaaMasoud,能否请您发布更多代码。 App.ViewModel 是 NewsViewModel 的一个实例吗? NewsRepository 有 List 属性吗?

标签: windows-phone-7 data-binding mvvm


【解决方案1】:
  1. NewsViewModelNewsRepository 都必须实现 INotifyPropertyChanged

  2. 如果您使用ObservableCollection&lt;obj&gt; 作为绑定源而不是自定义NewsRepository 对象会更容易。

【讨论】:

    猜你喜欢
    • 2015-12-07
    • 1970-01-01
    • 1970-01-01
    • 2019-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-06
    相关资源
    最近更新 更多