【发布时间】:2012-02-21 11:04:54
【问题描述】:
<ItemsControl ItemsSource="{Binding ExportFormat, UpdateSourceTrigger=PropertyChanged}" Grid.Column="1">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Content="{Binding}" Margin="5" Height="50" Width="70" Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Path=DataContext.setExportFormat, UpdateSourceTrigger=PropertyChanged}" CommandParameter="{Binding}"></Button>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
所以我在我的 xaml 中有该代码,并且该按钮被归档为字符串列表。根据用户在以前的 Usercontrol 上选择的内容,该项目将与不同的项目一起归档。问题是如果用户在第一次运行时选择一个选项,按钮将被正确填充,但如果用户返回并选择另一个选项,控件不会更新并显示与以前相同.. 我的英语不是最好的,但我想我可以让我理解!任何的想法?! PS:Button 上的 bindind 是只读属性,因此我无法将其定义为 Mode="TwoWay".. 我查看了调试,属性 ExportFormat 使用新项目获取更新,但用户控件仍显示第一个选项! !
真诚的 Rui Nunes
【问题讨论】:
-
ViewModel 上的 ExportFormat 类型是什么?
-
正如狒狒指出的那样——这是你的问题——ObservableCollection
通知订阅者(绑定)发生了一些变化——List 没有。 -
请不要将 SOLVED 编辑到标题中或将您的解决方案编辑到问题正文中。发布解决方案作为答案。
-
@ChrisF 好的,我会尽快发布解决方案,因为我没有 100 个代表,我必须等待至少 6 个小时才能回答我自己的问题!
标签: wpf vb.net binding tabcontrol