2009-07-16 8 views

Antwort

10

@ Antwort Brandon hätte gearbeitet, aber ich denke, das ist ein wenig mehr elegant ist:

<ComboBox Name="AvailableStyles"> 
    <ComboBoxItem Tag="{x:Null}" IsSelected="True">None</ComboBoxItem> 
    <ComboBoxItem Tag="{StaticResource FirstStyle}" Style="{StaticResource FirstStyle}">Style 1</ComboBoxItem> 
    <ComboBoxItem Tag="{StaticResource SecondStyle}" Style="{StaticResource SecondStyle}">Style 2</ComboBoxItem> 
    <ComboBoxItem Tag="{StaticResource ThirdStyle}" Style="{StaticResource ThirdStyle}">Style 3</ComboBoxItem> 
</ComboBox> 

<Button Style="{Binding ElementName=AvailableStyles, Path=SelectedItem.Tag}" Content="Dynamically Styled Button" /> 
7

Sie können einfach den Stil im Code hinter setzen.

button.Style = (Style)FindResource("NameOfYourStyle"); 
+0

dies nicht funktioniert für me..the Ressource gefunden wird, aber nichts passiert und der Stil nicht angewendet wird .. :/ irgendein Rat? Vielen Dank – piggy

Verwandte Themen