开发者

wpf add dynamic resource programmatically C#

开发者 https://www.devze.com 2023-02-25 12:03 出处:网络
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

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");
0

精彩评论

暂无评论...
验证码 换一张
取 消