Simplified architecture of my Silverlight app:
- MainPage; DataContext set to MainViewModel
- MainPage has two elements: UserControl and Rectangle
- in MainViewModel, I have two properties, UserControlVisible and RectVisible, both of type Visibility, binded to Visibility properties of those two elements in MainPage.XAML
- MainViewModel has INotifyPropertyChanged implemented
Problem is, when I set RectVisible property in MainViewModel to Visibility.Collapsed, Rectangle hides, which is fine, but when I set Visibility.Collapsed to UserControl (UserControlVisible property), it never hides!
I cannot hide that user control, and I have to do it through my ViewModel class. Why it works with Rectangle element, but not with UserControl? When I manually set Visibility to Collapsed in XAML, then it's hidden, but I have to do it through code and ViewModel object.
(edit) Temporary sollution:
I manually subscribed to PropertyChanged event in codebehind
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
viewmodel=new MainViewModel();
this.DataContext = viewmodel;
// fix for binding bug:
viewmodel.PropertyChanged += viewmodel_PropertyChanged;
}
void viewmodel_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == "LoginVisible")
loginWindowControl.Visibility = viewmodel.LoginVisible;
}