我想在 C# Windows Phone 编程中使用 FindResource()
来更改控件的样式,但我做不到。
play_btn.Style = FindResource("btnplay") as Style;
这给出了一个错误:在当前上下文中不存在。
最佳答案
如果您的样式在 App.xaml 的 Resources
中定义,则必须使用:
play_btn.Style = App.Current.Resources["btnplay"] as Style;
否则(例如 MainPage.xaml、SecondPage.xaml ...):
play_btn.Style = this.Resources["btnplay"] as Style;
或者您可以将 TryFindResource
实现为扩展方法:“How to implement the missing TryFindResource ”。
关于c# - 为什么我不能在 Windows 手机编程中使用 FindResource()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20259770/