我的XAML设置有点复杂:
<UserControl.Resources>
<local:SuperCoolObject x:Key="firstObject"/>
<local:TotallyHotObject x:Key="secondObject"/>
</UserControl.Resources>
<Grid>
<ItemsControl ItemsSource="{Binding Path=MyItems, Source={StaticResource firstObject}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<DataTemplate.Resources>
<lol:MyConverter x:Key="myConverter" Equals="{Binding Path=SelectedItem, Source={StaticResource secondObject}}" />
<Style x:Key="On" TargetType="local:ThemedImage">
<Setter Property="Visibility" Value="Hidden"/>
<Style.Triggers>
<DataTrigger Binding="{Binding Converter={StaticResource myConverter}}" Value="True">
<Setter Property="Visibility" Value="Visible" />
</DataTrigger>
</Style.Triggers>
</Style>
</DataTemplate.Resources>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
(我省略了实际的DataTemplate)
请注意ItemsControl
ItemsSource
绑定到firstObject
和myConverter
绑定到secondObject
的方式。我需要做的是在ItemsSource
绑定(myConverter
)属性更改时进行secondObject.SelectedItem
绑定刷新。
所有适当的属性都设置为绑定属性,但我需要某种方式或强制{X}在{1}}中刷新。