【发布时间】:2015-10-19 08:05:50
【问题描述】:
我在代码后面创建按钮,现在必须使用 xaml 中的样式,如何在 c# 中为我的按钮调用该样式?
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.Loaded += OnLoaded;
}
private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
{
var button1 = new Button();
TestPanel.Children.Add(button1);
}
}
}
样式是<Style x:Key="ButtonStyle" TargetType="{x:Type Button}">
【问题讨论】:
标签: c# wpf xaml styles code-behind