如何在TabControl上设置椭​​圆样式触发器以突出显示DataGrids何时选择

时间:2017-09-05 01:22:30

标签: wpf xaml tabcontrol datatrigger ellipse

我在每个Ellipse标题中都有一个TabControl,如果在其下面的DataGrid中选择了任何项目,则会突出显示蓝色,否则它应该是透明的。目前我的Trigger是反向的,所以如果DataGrid SelectedItems.Count为0,则它​​是透明的,如果有某种方式将默认设置为透明,那将是不错的。

注意:它会有多个标签并关联DataGrids

如何让Style TriggerEllipse上正常使用?

enter image description here

<TabControl Name="tcGeometry" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5" ItemsSource="{Binding GEOMETRIES}" >
    <TabControl.ItemTemplate>
        <DataTemplate>
            <Grid>                            
                <TextBlock Text="{Binding DISPLAY_NAME}" Margin="0,0,25,0"/>
                <Ellipse x:Name="SelectionIndicator"
                         Width="8" Height="8"
                         Stroke="Black"
                         Fill="Blue"
                         StrokeThickness="1"
                         HorizontalAlignment="Right"
                         VerticalAlignment="Top">
                    <Ellipse.Style>
                        <Style TargetType="{x:Type Ellipse}">
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding  SelectedItems.Count, ElementName=dgAudit}"  Value="0">
                                    <Setter Property="Fill" Value="Transparent" />
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </Ellipse.Style>
                </Ellipse>
            </Grid>
        </DataTemplate>
    </TabControl.ItemTemplate>
    <TabControl.ContentTemplate>
        <DataTemplate>
            <Grid ShowGridLines="False">
                <DataGrid Name="dgAudit" 
                          Grid.Row="0"
                          Grid.Column="0"
                          IsReadOnly="True"
                          ItemsSource="{Binding GEOM_ASSET_OC_LIST}"
                          HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"
                          AutoGenerateColumns="False"
                          HorizontalAlignment="Stretch"
                          VerticalAlignment="Stretch"
                          RowDetailsVisibilityMode="Collapsed"
                          RowHeaderWidth="30" />
            </Grid>
        </DataTemplate>
    </TabControl.ContentTemplate>
</TabControl>

1 个答案:

答案 0 :(得分:1)

不要为Fill的{​​{1}}属性设置本地值。在Ellipse设置器中设置默认值。

Style

本地值优先于样式中设置的值:https://docs.microsoft.com/en-us/dotnet/framework/wpf/advanced/dependency-property-value-precedence

您可能还必须绑定到源集合<Ellipse x:Name="SelectionIndicator" Width="8" Height="8" Stroke="Black" StrokeThickness="1" HorizontalAlignment="Right" VerticalAlignment="Top"> <Ellipse.Style> <Style TargetType="{x:Type Ellipse}"> <Setter Property="Fill" Value="Blue" /> <Style.Triggers> <DataTrigger Binding="{Binding SelectedItems.Count, ElementName=dgAudit}" Value="0"> <Setter Property="Fill" Value="Transparent" /> </DataTrigger> </Style.Triggers> </Style> </Ellipse.Style> </Ellipse> 属性,该属性会跟踪所选项,而不是绑定到{Count的{​​{1}}属性。 1}}元素。这是因为默认情况下SelectedItems会在切换标签时卸载取消选择标签的可视树:

How to stop Wpf Tabcontrol to unload Visual tree on Tab change