0

我有一个 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>

请帮助任何人

4

2 回答 2

0

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

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

于 2013-02-07T03:10:46.400 回答
0

尝试更改设置器,以便它们使用 Property="Fill" 而不是 Property="Rectangle.Fill"

于 2013-02-07T02:41:08.443 回答