在我的DataTriggerBehavior
ChangePropertyAction
无效。
看来,当ActualWidth发生变化时,触发器不会收到通知。
这是我的代码,有什么建议吗?
<DataTemplate x:Name="ElementStyle">
<Canvas x:Name="UiControl" Background="Green">
<!-- Content -->
<ItemsControl x:Name="itemsControl" Height="20" Canvas.Left="10" Canvas.Top="11" ItemsSource="{Binding MyObservableCollection}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Rectangle Visibility="{Binding IsSelected, Converter={StaticResource BooleanToVisibilityConverter}}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<!-- Triggers -->
<interactivity:Interaction.Behaviors>
<core:DataTriggerBehavior Value="0.0" Binding="{Binding ActualWidth, ElementName=itemsControl}" ComparisonCondition="GreaterThan">
<core:ChangePropertyAction TargetObject="{Binding ElementName=UiControl}" PropertyName="Background" Value="White" />
</core:DataTriggerBehavior>
<core:DataTriggerBehavior Value="0.0" Binding="{Binding ActualWidth, ElementName=itemsControl, Mode=OneWay}" ComparisonCondition="Equal">
<core:ChangePropertyAction TargetObject="{Binding ElementName=UiControl}" PropertyName="Background" Value="Blue" />
</core:DataTriggerBehavior>
</interactivity:Interaction.Behaviors>
</Canvas>
</DataTemplate>
我检查了ActualWidth,如果显示其中一个矩形,它会改变。