我在xaml中有一个controltemplate,目标是ToogleButton,x:Key =“NewBtn”
请使用控制模板中的模板帮助我在C#代码中创建一个toogle按钮 如果在xaml代码中这是代码:
<ToggleButton Template="{DynamicResource NewBtn}"
Margin="12,21,0,0" HorizontalAlignment="Left" Width="151" Height="29" VerticalAlignment="Top"
x:Name="newBtn"
Checked = newBtn_Checked Unchekcked = newBtn_Unchecked
/>
请帮我介绍如何在c#
中创建它答案 0 :(得分:2)
var button = new ToggleButton
{
Margin = new Thickness(12, 21, 0, 0),
HorizontalAlignment = HorizontalAlignment.Left,
Width = 151,
Height = 29,
VerticalAlignment = VerticalAlignment.Top,
Name = "newBtn",
};
button.SetResourceReference(Button.TemplateProperty, "NewBtn");
或
ToggleButton button = new ToggleButton();
button.Margin = new Thickness(12, 21, 0, 0);
button.HorizontalAlignment = HorizontalAlignment.Left;
button.Width = 151;
button.Height = 29;
button.VerticalAlignment = VerticalAlignment.Top;
button.Name = "newBtn";
button.SetResourceReference(Button.TemplateProperty, "NewBtn");