ChangePropertyAction的DataTriggerBehavior无法正常工作

时间:2014-03-27 08:37:16

标签: c# xaml windows-runtime windows-8.1

在我的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,如果显示其中一个矩形,它会改变。

0 个答案:

没有答案