I’ve been trying to set the visibility of a stackpanel from my viewmodel but haven’t had much luck. Heres my XAML:
<StackPanel Visibility="{Binding Path=IsVisible}"/>
Note: I have successfully connected my view to my viewmodel. All my other properties are binding correctly.
Heres my ViewModel Code:
private Visibility isVisible;
public Visibility IsVisible
{
get
{
return isVisible;
}
set
{
isVisible = value;
RaisePropertyChanged("IsVisible");
}
}
This approach has worked for every other property I’ve been using with no problem. I just can’t get the visibility to transfer. Any suggestions?
Works on my machine 😀
I know, not a great answer. Maybe looking at the sample code I’ve got will help out though:
Setting the datacontext to the MainViewModel and binding IsVisible on the stackpanel. I’ve also bound the button to a command that will change the IsVisible property to Collapsed:
(XAML)
No codebehind to show of course.
And the IsVisible property and the MakeVisibleCommand property on the view model:
Of course, make sure your view model class inherits from ViewModelBase and all that jazz. You’ve already mentioned that your other properties are bound correctly, but its always good to keep an eye on the Output window for binding errors when you’re debugging.
Hopefully that helps out!