2008-12-04 45 views
5

我需要在代碼艾克應用樣式這樣的:如何在運行時在代碼中應用動態樣式?

TextBlock.Style = TryFindResource("MyStyle") as Style; 

當資源的詞典改變,將動態更新(即皮膚被替換在運行時)。換句話說,我需要相當於使用動態資源這樣的:

<TextBlock Style="{DynamicResource MyStyle}" /> 

回答

13

嘗試使用SetResourceReference

textBlock.SetResourceReference(TextBlock.StyleProperty, "MyStyle") 
相關問題