绑定用户控件内LongListSelector当前项目 [英] Binding user control inside LongListSelector with current Item
问题描述
这是我在做什么。
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>
我希望我的后览
内部控制与当前的ItemsSource元的性质的约束。但是,什么情况是,说我有设置的ItemsSource,我在发布的每一个元素
观点得到5个值5对象的列表。
I want controls inside my PostView
to be bound with properties of Current ItemsSource element. But whats happening is, say I have List of 5 objects set as ItemsSource, every element in my Post
view gets 5 values.
所以我得到的,而不是1月25日PostViews初始化,5元的ItemsSource对象。
So I am getting 25 PostViews initialized, 5 per ItemsSource object, instead of 1.
下面是我的 PostView.xaml
是它可以帮助
Here is my PostView.xaml
is it helps
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>
用户在模型中,我绑定到一个对象的属性。
我怎样才能解决这个问题?
User is an Object property in the model I am binding to. How can I fix it?
推荐答案
拿了帮助的<一个href=\"http://stackoverflow.com/questions/16998578/how-to-bind-data-user-control-inside-listbox-wp8\">this帖子设置为我的数据的依赖领域 PostView.xaml.cs
和 UserControl.xaml $设置它C $ C>
Took help from this post to set up a dependency field for my data in PostView.xaml.cs
and set it up from UserControl.xaml
这篇关于绑定用户控件内LongListSelector当前项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!