所以我有这个控制模板,我想要signalnamepanel(只是时间标签,我将在它旁边添加一个x轴)只有在项目绑定到Treeview时才会显示。
否则它看起来会很奇怪,因为namepanel会自动浮动。我猜我需要使用某种触发器,但我不确定我会触发什么。
<Style x:Key="{x:Type TreeView}" TargetType="TreeView">
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TreeView">
<ScrollViewer
Focusable="False"
CanContentScroll="False"
Padding="4">
<StackPanel>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="19" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="{Binding ElementName=graph_viewer, Path=signal_graph_window_width, Mode=OneWay}" />
</Grid.ColumnDefinitions>
<wpfExp:SignalNamePanel Grid.Column="1"
Height="{Binding ElementName=graph_viewer, Path=GraphHeight, Mode=OneWay}"
MainText="Time"
/>
<wpfExp:SignalGraphAxis Grid.Column="2"
Height="{Binding ElementName=graph_viewer, Path=GraphHeight, Mode=OneWay}"
PenWidth="{Binding ElementName=graph_viewer, Path=GraphPenWidth, Mode=OneWay}"
X_Scale="{Binding ElementName=graph_viewer, Path=X_Scale, Mode=OneWay}"
MaxTimeValue="{Binding ElementName=graph_viewer, Path=_SignalDataViewModel.MaxTimeValue, Mode=OneWay}"
/>
</Grid>
<ItemsPresenter/>
</StackPanel>
</ScrollViewer>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver"
Value="True">
<Setter TargetName="ExpandPath"
Property="Stroke"
Value="#FF1BBBFA"/>
<Setter TargetName="ExpandPath"
Property="Fill"
Value="Transparent"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
答案 0 :(得分:5)
您好您可以在Trigger中使用HasItems。
XAML:
<Trigger Property="ItemsControl.HasItems" Value="True">
<Setter Property="Visibility" TargetName="Name" Value="Collapsed"/>
</Trigger>