2012-02-12 11 views
1

私はリストボックスのスタイルを設定したSilverlightアプリケーションを使用しています。これは、アプリケーション全体でListBoxItemのスタイルの一部です:Silverlightでテンプレートを使用してアプリケーション全体のスタイルをオーバーライドします。

<VisualStateGroup x:Name="CommonStates"> 
    <VisualState x:Name="Normal" /> 
    <VisualState x:Name="MouseOver"> 
     <Storyboard> 
      <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ListBoxItemGrid" Storyboard.TargetProperty="Background" Duration="0"> 
       <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource MouseOverColorBrush}" /> 
      </ObjectAnimationUsingKeyFrames> 
     </Storyboard> 
    </VisualState> 
</VisualStateGroup> 

は今、私は、ユーザーがListBoxItemの上に置いたときに何も起こりませんしたい別のリストボックスを持っています。私はこれを試した:

<VisualStateGroup x:Name="CommonStates"> 
    <VisualState x:Name="Normal" /> 
    <VisualState x:Name="MouseOver" /> 
</VisualStateGroup> 

しかし、それは動作していないようです。どのようにデフォルトのアプリケーション全体のスタイルを上書きできますか?私は関連性があるかどうかはわかりませんが、アプリケーション全体のスタイルはスタイルですが、私の '特別な'リストボックスはListBoxItemのテンプレートを持っています。

答えて

1

見つけました。私はコンテナにスタイルを与えなければならなかった:

<ListBox Grid.Row="1" 
    ItemsSource="{Binding TheItems}" 
    ItemContainerStyle="{StaticResource TheLineStyle}" 
    ItemTemplate="{StaticResource TheItemTemplate}"></ListBox> 


<Style TargetType="ListBoxItem" x:Key="TheLineStyle"> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="ListBoxItem"> 
       <Grid> 
        <ContentControl Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" /> 
        <VisualStateManager.VisualStateGroups> 
         <VisualStateGroup x:Name="CommonStates"> 
          <VisualState x:Name="Normal" /> 
          <VisualState x:Name="MouseOver" /> 
         </VisualStateGroup> 
        </VisualStateManager.VisualStateGroups> 
       </Grid> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
</Style> 
関連する問題