Given:
<StackPanel>
<View:ArcController x:Name="control1" Visibility="{Binding Path=CanShowDateControl, Converter={StaticResource bool2VisibilityConverter}}" />
<my1:DateLabelView x:Name="control2" DataContext="{Binding Path=DateLabelViewModel}" Visibility="{Binding ElementName=ctrlTableToolbar, Path=DataContext.IsDateReadOnly, Converter={StaticResource bool2VisibilityConverter}}" />
</StackPanel>
I have two controls (control1 and control2) inside the stack panel, and at one point I want to show only one control. As shown in the code, the visibility of the controls is controlled by "IsDateReadOnly" and "CanShowDateControl". And according to my viewmodel logic ... CanShowDateControl =! IsReadOnly.
So, at one time, I will ONLY show one of the two controls.
Question: My problem is that while I show only one control, my xaml instantiates both controls. Is it possible to instantiate only the control that I am showing?
Give this:
1) I want to show / hide the use of binding, so the logic lies in my view model. 2) I can save these two controls inside one wrapper control. Since I use it in different places.
Thank you for your interest.
source
share