So I have three views created with usercontrol in wpf. And I created 3 buttons to change views.
MainWindow.xaml.cs
private void view1_clicked(object sender, RoutedEventArgs e)
{
DataContext = new view1model1();
}
private void view2_clicked(object sender, RoutedEventArgs e)
{
DataContext = new viewmodel2();
}
private void view3_clicked(object sender, RoutedEventArgs e)
{
DataContext =new view1model3();
}
And Lets say I have textblock in view2 and its visibility is collapsed on purpose when I clicked view2 at the first time.
public Classification()
{
InitializeComponent();
if(condition == null)
{
someControl.Visibility = Visibility.Collapsed;
}
private void condition_changed(object sender, SelectionChangedEventArgs e)
{
if(someControl.Visibility == Visibility.Collapsed)
{
someControl.Visibility = Visibility.Visible;
}
}
And In view2, There is a condition control that triggers someControl.visibility = collapsed to visible.
But the problem is when I clicked view3 or view1 and then come back to view2 , somecontrol is changed to collapsed.
I know it is because I set 'someControl' to collapsed in the constructor. But I can't figure it out how to make it work as I wish.
To make it short, I want to set somecontrol.visibility to collapsed at the begining, but once it is changed to visible after triggering condition, I want to keep it visible until I clicked refresh button in view2 which I'm going to create later.