D
D
Drottarutarnum2020-03-28 20:36:37
WPF
Drottarutarnum, 2020-03-28 20:36:37

How to create an element in code in MVVM?

Here I am creating a button in my VM

Button myButton = new Button();
myButton.Width = 100;
myButton.Height = 30;
myButton.Content = "Кнопка";


I could insert it in the right place with code like this:
layoutGrid.Children.Add(myButton);

But I want to decide inside the XAML where it will be, something like How to achieve this?
<Button Source="{Binding myButton}" />

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
d-stream, 2020-03-28
@d-stream

<Button Width="100" Height="30" Content="{Bindind ButtonText}" Command="{Binding ButtonCommand}"   />

And you get an honest layout of the design in xaml, and the behavior in the code

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question