这就是我正在做的。将LongListSelector内部的用户控件绑定到当前项目
UserControl.xaml
<Grid x:Name="LayoutRoot" Background="{StaticResource PhoneChromeBrush}">
<phone:LongListSelector
Name="MainList"
ItemsSource="{Binding}">
<phone:LongListSelector.ItemTemplate>
<DataTemplate>
<StackPanel>
<views:PostView
DataContext="{Binding ElementName=MainList, Path=ItemsSource}">
</views:PostView>
</StackPanel>
</DataPanel>
我想在我的PostView
与当前的ItemsSource元素的属性来绑定控件。但是最新发生的事情是,例如我有5个对象列表设置为ItemsSource,我的Post
视图中的每个元素都获得5个值。
所以我得到25个PostViews初始化,5元的ItemsSource对象,而不是1
这是我PostView.xaml
是它有助于
PostView.xaml
<Grid x:Name="LayoutRoot" Background="{StaticResource PhoneBackgroundBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<ItemsControl
ItemsSource="{Binding}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Path=User.Username, Mode=OneWay}" />
</StackPanel>
用户是我绑定到的模型中的Object属性。 我该如何解决它?
设置它我试着用'{结合}'更早,只是试图'的DataContext =“{绑定的ElementName = MainList,路径=的SelectedItem}“'。但它不工作。有了这个,PostView甚至没有被初始化。 – PratPor 2014-10-10 14:42:35
我刚刚更新了我的问题,给出了PostView.xaml的概念 – PratPor 2014-10-10 14:57:58