這就是我正在做的。將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