2009-03-08 17 views
1

に範囲外のコントロールのスタイルを変更する:WPFはトリガ:私はXAMLでこの問題の解決策を考え出すことができないトリガー

私は特定の右ボタンの幅をアニメーション化します左ボタンのIsMouseOverが真のときの値。私はどこにこれを置くべきかわからない:ボタンの1つのスタイルまたはテンプレート、またはグリッドのスタイルで。それも可能ですか?

<Border Style="{StaticResource ContentBodyStyle}" x:Name="Border" > 
    <Grid Width="Auto" Height="Auto" Style="{DynamicResource GridStyle1}"> 
     <Grid.ColumnDefinitions> 
     <ColumnDefinition/> 
      <ColumnDefinition/> 
     </Grid.ColumnDefinitions> 
     <Button Margin="0,0,0,0" Content="Button" Grid.Row="0" x:Name="BtnLeft" Style="{DynamicResource ButtonStyle1}"/> 
     <Button Margin="0,0,0,0" Content="Button" Grid.Column="1" x:Name="BtnRight" Width="0"/> 
    </Grid> 
</Border> 

おかげ

答えて

3

私はあなたがそれに割り当てられたスタイルを持つコントロールの範囲外のコントロールのプロパティを設定することができますかわかりません。それが可能であっても、それは正しいとは思わない。 シナリオでできることは、イベントトリガーとストーリーボードを両方のボタンに表示される場所で使用することです。ここで私は、必要に応じて再利用可能にするために、ツリーまで少しさらにストーリーボードを置くことを好むだろうが、BtnLeftを変更する方法の例です:

<Button Margin="0,0,0,0" Content="Button" Grid.Row="0" x:Name="BtnLeft" Style="{DynamicResource ButtonStyle1}"> 
    <Button.Resources> 
     <Storyboard x:Key="OnMouseEnter1"> 
      <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" 
       Storyboard.TargetName="BtnRight" 
       Storyboard.TargetProperty="Width"> 
       <SplineDoubleKeyFrame KeyTime="00:00:00.5" Value="75"/> 
      </DoubleAnimationUsingKeyFrames> 
     </Storyboard> 
     <Storyboard x:Key="OnMouseLeave1"> 
      <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" 
       Storyboard.TargetName="BtnRight" 
       Storyboard.TargetProperty="Width"> 
       <SplineDoubleKeyFrame KeyTime="00:00:00.5" Value="0"/> 
      </DoubleAnimationUsingKeyFrames> 
     </Storyboard> 
    </Button.Resources> 
    <Button.Triggers> 
     <EventTrigger RoutedEvent="Mouse.MouseEnter" SourceName="BtnLeft"> 
      <BeginStoryboard Storyboard="{StaticResource OnMouseEnter1}"/> 
     </EventTrigger> 
     <EventTrigger RoutedEvent="Mouse.MouseLeave" SourceName="BtnLeft"> 
      <BeginStoryboard Storyboard="{StaticResource OnMouseLeave1}"/> 
     </EventTrigger> 
    </Button.Triggers> 
</Button> 

代わりIsMouseOverプロパティの、あなたはMouseEnterイベントとMouseLeaveを使用することができますイベント。それはあなたに同じ機能を与えるはずです。

編集:EventTriggerのプロパティは、ボタンのスコープ内でトリガーが定義されているときに省略することができます。

+0

ありがとうございました。 –

関連する問題