0

I'm trying to set a part of a View dynamically based on a value selected. I've already managed to set the View and ViewModel with xaml like this:

    <DataTemplate DataType="{x:Type vm:MyViewModel}">
        <v:MyUserControl />
    </DataTemplate>
...

<ContentControl Content="{Binding MyViewModel}" />

But this doesn't seem very flexible as I have to add new types to the View every time I get new values to the list.

I think something more dynamic should be possible with Catel (3.9). Like the one in this question: How Instantiate Control Programmatically in Catel

I already tried binding to the ViewModel but Catel doesn't seem to recognize the UserControls and doesn't instantiate the View. Are there any other ways to do this?

Community
  • 1
  • 1
kor_
  • 1,510
  • 1
  • 16
  • 36

1 Answers1

1

I think you are looking for the ViewModelToViewConverter which does all of this automatically for you.

Geert van Horrik
  • 5,689
  • 1
  • 18
  • 32
  • Well, almost perfectly: when I set the bound value to null, the last active View stays visible. Initially when the view is null the View is empty. Is there a way to set the View to null so that nothing is visible? – kor_ Mar 17 '17 at 12:25
  • 1
    You can copy / derive the converter and change the behavior. In the end it's all open source ;-) – Geert van Horrik Mar 20 '17 at 11:13