所以,我有這個本地刷資源,我將用於我的一些stackpanels,我想知道如何在c#類中訪問它。我將創建stackpanels,我需要設置背景的StackPanel的在C#使用ThemeResources更改stackpanel.background
在XAML控件的背景可通過輕鬆設置:
Background="{ThemeResource SubPanelBackground}"
但我無法找到一種在C#中實現它的方式,因爲我將按需創建一些控件。這裏是一個代碼片段
StackPanel Group2Panel = new StackPanel();
Group2Panel.Orientation = Orientation.Horizontal;
Group2Panel.Height = 80;
Group2Panel.Margin = new Thickness(10);
Group2Panel.Background = /*Now i cant find what to enter here*/;
任何人都可以找到我應該進入的那個找到themeresource刷嗎?
有沒有辦法做到這一切在一行 還因爲我將使用一對夫婦不同的主題資源可以聲明多個themeResources – Albert
@GurfX Group2Panel.Background = Resources [「SubPanelBackground」]作爲刷子< - 這是你的意思嗎? – tgpdyk
是的,這就是我的意思,我認爲代碼都可以工作,但是這個錯誤發生。 '在mscorlib.ni.dll中發生類型'System.Runtime.InteropServices.COMException'的異常,但未在用戶代碼中處理 WinRT信息:找不到具有給定鍵的資源。 附加信息:未指定的錯誤' – Albert