D
D
DarkByte20152016-04-25 08:05:37
WPF
DarkByte2015, 2016-04-25 08:05:37

How to split XAML code?

Is it possible to somehow split a large XAML code into several view files? I even saw it somewhere already, i.e. is done for each UserControl view. But most importantly, what will happen to the binding? Because if you specify the same ViewModel as the DataContext everywhere, then a new Instance will still be created for each view ... Is it possible to somehow intercept the parent instance of the DataContext?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
MonkAlex, 2016-04-25
@DarkByte2015

The DataContext descends from above anyway, you don't need to do anything extra for this.

V
Vyacheslav Zolotov, 2016-04-25
@SZolotov

You can bind controls to the DataContext of the parent control. Google the ElementName parameter of the binding

B
bimo, 2016-04-25
@bimo

use the ContentControl class in the xaml of the main window/control to which you bind your UserControls (eg mainViewModel.SelectedControl = new MyUserControl()). DataContext is thrown by itself, it needs to be set only at the main window/control

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question