B
B
BadCats2017-07-09 17:32:47
WPF
BadCats, 2017-07-09 17:32:47

Access an element in XAML markup?

Have StackPanel

StackPanel sp = new StackPanel
            {
                Width = MainGrid.ActualWidth,
                Height = MainGrid.ActualWidth,
                
            };

How to refer to this instance in XAML markup?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mikhail Usotsky, 2017-07-09
@BadCats

By name: Name="".

R
Roman, 2017-07-10
@yarosroman

If you dynamically add a control, then there is no way, because at first the XAML "constructor" works out, and then you add your own control and the "constructor" simply does not know anything about it. As an option, dynamically build XAML and pass it to the "constructor", but there are a lot of restrictions.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question