1
我試圖創建一個大多不透明的GridSplitter
,然後在mouseover上使動畫變得完全可見。以下是我已經試過:在GridSplitter中使用數據觸發器
風格:
<Style x:Key="SplitterStyle" TargetType="{x:Type GridSplitter}">
<Setter Property="Opacity" Value="0.2" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type GridSplitter}">
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity" To="1" Duration="0:0:0.2" />
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity" Duration="0:0:0.3" />
</Storyboard>
</BeginStoryboard>
</Trigger.ExitActions>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
GridSplitter
:
<GridSplitter
ResizeDirection="Columns"
Grid.Column="0"
Background="Red"
VerticalAlignment="Stretch"
Width="4"
Style="{StaticResource SplitterStyle}" />
我查MSDN和GridSplitter擁有所有我使用性質的,所以它看起來像它應該沒問題,但也許我忽略了一些明顯的東西?
編輯:
是否有可能把GridSplitter到另一個元素?我改變了我的風格:
<Style x:Key="SplitterStyle" TargetType="{x:Type Border}">
<Setter Property="Opacity" Value="0.2" />
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity" To="1" Duration="0:0:0.2" />
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Opacity" Duration="0:0:0.3" />
</Storyboard>
</BeginStoryboard>
</Trigger.ExitActions>
</Trigger>
</Style.Triggers>
</Style>
然後,我把GridSplitter到邊境和應用該樣式的邊界,而不是:
<Border
Style="{StaticResource SplitterStyle}"
Background="{StaticResource WindowBorderBrush}"
VerticalAlignment="Stretch"
Width="4"
Grid.Column="0"
HorizontalAlignment="Right">
<GridSplitter ResizeDirection="Columns" Background="Red" ResizeBehavior="CurrentAndNext"/>
</Border>
邊框的偉大工程!但是現在,GridSplitter無處可尋(紅色背景沒有顯示,當我將鼠標懸停在邊界上時,光標不會改變,並且沒有任何東西可以拖動來調整任何東西)。爲什麼是這樣?
編輯:
OK,我發現我已經指定GridSplitter
的寬度。此外,我將GridSplitter
的背景更改爲透明,因爲我從未計劃使用紅色。現在,它顯示並看起來很棒,但它實際上並沒有調整任何東西:P如何讓它實際上有用?