c# Windows phone 8如何为按钮添加样式
本文关键字:按钮 添加 样式 Windows phone | 更新日期: 2023-09-27 18:06:10
如何将app.xaml中的样式设置为c#中的按钮?
在app.xaml中有一个按钮样式,我想在c#中的按钮中使用它
这是我的代码按钮。
Button deleteButton = new Button();
deleteButton.Background = new ImageBrush
{
ImageSource ="Delete2.png"
};
deleteButton.Height = 70;
deleteButton.Width = 70;
deleteButton.HorizontalAlignment = HorizontalAlignment.Left;
deleteButton.VerticalAlignment = VerticalAlignment.Bottom;
deleteButton.Margin = new Thickness(0,10,0,-5);
deleteButton.BorderBrush = null;
deleteButton.Visibility = Visibility.Collapsed;
deleteButton.Click += new RoutedEventHandler(ItemDeleteButton_Click);
deleteButton.Tag = tag;
deleteButton.Style = ?????????????????
试试这个代码
deleteButton.Style = App.Current.Resources["StyleKey"] as Style;
您可以使用FindResource
或TryFindResource
资源和代码- MSDN
我解决了
deleteButton.Style = App.Current.Resources["ButtonStyle"] as Style;
您的Style
可能在应用程序的其他地方的ResourceDictionary
中定义。您可以使用FindResource
方法检索它:
deleteButton.Style = (Style)this.FindResource("MyCustomButtonStyle");