wpf add dynamic resource programmatically C#
i have a controltemplate in xaml and the target is ToogleButton with x:Key = "NewBtn"
please help me create a toogle button in C# code using template from the Control Template if in xaml code this is the code:
<ToggleButton Templ开发者_高级运维ate="{DynamicResource NewBtn}"
Margin="12,21,0,0" HorizontalAlignment="Left" Width="151" Height="29" VerticalAlignment="Top"
x:Name="newBtn"
Checked = newBtn_Checked Unchekcked = newBtn_Unchecked
/>
please help me how to create it in c#
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");
or
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");
精彩评论