0

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 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
                  />

please help me how to create it in c#

1 Answer 1

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

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");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.