Windows 8地铁从代码背后调用standardstyle

May*_*ank 2 c# xaml windows-8

我试图通过代码隐藏在StandardStyles.xaml中定义一个样式.

我试过了

var x = Resources["UnfavoriteAppBarButtonStyle"];
Run Code Online (Sandbox Code Playgroud)

但我在该代码上得到了COMException.

错误HRESULT E_FAIL已从调用COM组件返回.

如果上面的代码错误,我怎么能从StandardStyles.xaml访问样式

May*_*ank 7

我知道了

正确的方法是:

var style = Application.Current.Resources["FavoriteAppBarButtonStyle"] as Style
Run Code Online (Sandbox Code Playgroud)