为什么数据触发器没有触发

时间:2013-02-07 01:34:18

标签: wpf xaml

我有一个XAML代码。我试图在Datatrigger上填充矩形,但它没有触发

<ItemsControl Grid.Row="1" Grid.Column="1" ItemsSource="{Binding SelectedEnrollments}" Visibility="{Binding EnrollmentsExist, Converter={x:Static s:BooleanToVisibilityConverter.Default}, Mode=TwoWay}">
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <RadioButton Tag="{Binding Id}" GroupName="Enrollments" ToolTip="{Binding Title}" Checked="EnrollmentRadioButton_Checked" IsChecked="{Binding IsSelected}">
                <RadioButton.ContentTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">

                            <TextBlock TextTrimming="CharacterEllipsis" 
                                       Text="{Binding ToolTip, RelativeSource={RelativeSource FindAncestor, AncestorType=RadioButton}}" />
                            <Rectangle x:Name="RankIcon" Width="30">
                                <Rectangle.Style>
                                    <Style>
                                        <Style.Triggers>
                                            <DataTrigger Binding="{Binding Rank}" Value="Primary">
                                                <Setter  Property="Rectangle.Fill" Value="Blue"></Setter>
                                            </DataTrigger>
                                            <DataTrigger Binding="{Binding Rank}" Value="Secondary">
                                                <Setter  Property="Rectangle.Fill" Value="{DynamicResource IconRankSecondary}"></Setter>
                                            </DataTrigger>
                                        </Style.Triggers>
                                    </Style>
                                </Rectangle.Style>
                            </Rectangle>
                         </StackPanel>
                        <DataTemplate.Triggers>

                        </DataTemplate.Triggers>
                    </DataTemplate>
                </RadioButton.ContentTemplate>
            </RadioButton>
        </DataTemplate>
    </ItemsControl.ItemTemplate>
</ItemsControl>

请帮助anypne

2 个答案:

答案 0 :(得分:0)

尝试更改setter,以便他们使用Property =“Fill”而不是Property =“Rectangle.Fill”

答案 1 :(得分:0)

将数据触发器移动到页面或视图的资源中。我相信它可能会被触发但是Value =“{DynamicResource IconRankSecondary}”的绑定可能无法找到DynamicResource。

通过在调试模式下运行数据绑定并查看指定绑定失败的调试输出来验证数据绑定问题。