Reputation: 976
I have a requirement to be able to swap out an instance of a view at runtime, depending on certain conditions.
I can achieve this in the code behind and building the UI by code (resolving the interface in InitializeComponent, for example), but my preference would be to place the item in XAML as a reference to an interface that is then resolved at runtime. I feel XAML is a better way of expressing bindings and property assignment than doing the same in code.
Please note - I am not trying to control the visibility of the control. I am trying to control what implementation of the control is used.
Is this possible?
Upvotes: 0
Views: 72
Reputation: 8090
Depending how complicated, I may just hide/show views. (Binding IsVisible to something)
If you want something more complicated and xaml-y, then you could use a data template selector, and then render the template. I created a sample of this here:
https://github.com/curtisshipley/DataTemplateControl
Upvotes: 1
Reputation: 7189
You can make use of the property IsVisible
in XAML , and bind that to a property in your ViewModel. Using that, you can either have view1 visible, or view2 visible, for example.
Upvotes: 0