Xaml assessing phone:PhoneApplicationPage.Resources来自wp8背后的代码
PhoneApplicationPage.Resources标记中我的项目的.xaml页面中声明了一些样式 如何在windows phone 8中的代码隐藏中访问这些样式Xaml assessing phone:PhoneApplicationPage.Resources来自wp8背后的代码,xaml,windows-phone-8,code-behind,Xaml,Windows Phone 8,Code Behind,PhoneApplicationPage.Resources标记中我的项目的.xaml页面中声明了一些样式 如何在windows phone 8中的代码隐藏中访问这些样式 <phone:PhoneApplicationPage.Resources> <Stlye x:key="Mystlye" TargetType = "Button"> ..... </Style> </phone:PhoneApplicationPage.Reso
<phone:PhoneApplicationPage.Resources>
<Stlye x:key="Mystlye" TargetType = "Button">
.....
</Style>
</phone:PhoneApplicationPage.Resources>
.....
现在我想访问codebehind中的Mystlye。。。如何做到这一点?var style=Resources[“Mystlye”];
- 要访问应用程序级资源(在app.xaml/inside
中定义),请使用:
Application.Current.Resources[“MyResources”]
- 要访问应用程序页面级资源(在thispage.xaml/inside
中定义),请使用:
Resources[“MyResources”]
如果上面的一个不起作用,请确保强制转换为Styletry following,如果起作用,请接受作为答案。var style=(style)Application.Current.Resources[“Mystlye”];
btn.Style = Application.Current.Resources["Mystlye"] as Style;