我在每个Ellipse
标题中都有一个TabControl
,如果在其下面的DataGrid
中选择了任何项目,则会突出显示蓝色,否则它应该是透明的。目前我的Trigger
是反向的,所以如果DataGrid
SelectedItems.Count
为0,则它是透明的,如果有某种方式将默认设置为透明,那将是不错的。
注意:它会有多个标签并关联DataGrids
。
如何让Style
Trigger
在Ellipse
上正常使用?
<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>
答案 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