2012-05-02 26 views
2

例如,我有一個風格的元素,並與我想改變特定資源如何改變通過XAML動態資源值(觸發器爲例)

<Style x:Key="MyStyle" TargetType="{x:Type Tree:MyListBox}"> 
    <Style.Triggers> 
     <DataTrigger Binding="{Binding Property}" Value="ItemSelected"> 
      <Setter Property="MydinamicResourceKey" Value="NewValue"/> 
     </DataTrigger> 
    </Style.Triggers> 
</Style> 

是否有可能觸發?

+0

對此有任何答案? – Sankarann

+0

更改資源是不可能的。因此,通過兩種方式來達到動態變化的道具是可能的:來自Microsoft.Expression.Interactions的DataTrigger(http://sshumakov.com/2012/12/08/how-to-use-datatrigger-from-microsoft-expression-interactions/)或通過自定義綁定(http://wpftutorial.net/LocalizeMarkupExtension.html) –

回答

0

也許嘗試使用VisualStateManager?

這是Microsoft's ListBox Styles and Templates page

<Style x:Key="MyStyle" TargeType="{x:Type Tree:MyListBox}"> 
    <Setter Property="Template"> 
    <Setter.Value> 
     <ControlTemplate TargetType="{x:Type Tree:MyListBox}"> 
     <Border x:Name="Border"> 
      <VisualStateManager.VisualStateGroups> 
       <VisualStateGroup x:Name="SelectionStates"> 
       <VisualState x:Name="Unselected"/> 
       <VisualState x:Name="Selected"> 
        <Storyboard> 
         <ObjectAnimationUsingKeyFrames Storyboard.TargetName="myUIElementName" 
                 Storyboard.TargetProperty="myUIElementProperty"> 
          <DiscreteObjectKeyFrame KeyTime="0:0:0" Value="{DynamicResource MyResourceKey}"/> 
         </ObjectAnimationUsingKeyFrames> 
         </Storyboard> 
         </VisualState> 
        </VisualStateGroup> 
        </VisualStateManager.VisualStateGroups> 
        .... more code here.... 
        </Border> 
       </ControlTemplate> 
       </Setter.Value> 
       </Setter> 
      </Style> 

的想法,我有一個tutorial by Shawn Wildermuth bookmarked這種類型的動畫/更改的 - 我仍然提到了很多。

希望這是有幫助的,可以讓你朝着正確的方向前進。