沒有定義樣式我有myWindow.xaml在限定「myStyle的」 -是否有可能設定一個風格的代碼時在App.xaml中
<ResourceDictionary ...>
<Style x:Key="MyStyle" TargetType="{x:Type Window}">
//style definitions etc
</Style>
</ResourceDictionary>
myWindow.xaml只定義了風格,有沒有它的實例。
我想設置另一個窗口也使用myStyle的,即
otherWindow.Style = "MyStyle"
我不能改變otherWindow的XAML,只能從代碼中訪問它。 我也不能將樣式定義移動到app.xaml。
我發現了一個similar question,這裏的款式在App.xaml中定義,這是可以做到像所謂
Style style = Application.Current.Resources["myStyle"] as Style;
otherWindow.Style = style;
但是,因爲我的風格是不是在App.xaml中調用上面定義沒有按」工作(拋出未發現異常)。
如何將MyStyle設置爲另一個窗口的樣式?
你不能從MyWindow的資源中獲得樣式嗎? – Clemens
@ Clemens-我該如何編程? – Shtut
如果你有一個MyWindow的實例,按'window.Resources'。 – Clemens