I have a StackPanel that I would like to hide when there isn't a selected item from a ListView in the same window. Currently, when I open the window, there is no selected item and the StackPanel is hidden, but when I do select something from the ListView, no change occurs.
I am binding the SelectedItem in the ListView like:
<ListView
MinHeight="0"
MaxHeight="500"
Margin="10,10,10,0"
Background="#e7f5f4"
BorderThickness="0"
ItemsSource="{Binding Issues}"
ScrollViewer.HorizontalScrollBarVisibility="Hidden"
SelectedItem="{Binding SelectedIssue}"
SelectionMode="Single">
Where "SelectedIssue" is a custom class property in my ViewModel (my entire window has the same DataContext). I am currently binding the Visibility property of my StackPanel as:
<StackPanel
Grid.Column="1"
Margin="13,0,0,5"
VerticalAlignment="Bottom"
Background="#ebf7f6"
Orientation="Horizontal"
Visibility="{Binding SelectedIssue,
Converter={StaticResource NullToVisibilityConverter},
UpdateSourceTrigger=PropertyChanged}">
And my converter is:
public class NullToVisibilityConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return value == null ? Visibility.Collapsed : Visibility.Visible;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
What am I missing?
EDIT: Here is my getter/setter
private Issue _selectedIssue;
public Issue SelectedIssue
{
get { return _selectedIssue; }
set { Set(ref _selectedIssue, value); }
}
public void RaisePropertyChanged([CallerMemberName]string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public bool Set<T>(ref T storage, T value, [CallerMemberName]string propertyName = null)
{
if (Equals(storage, value))
return false;
storage = value;
RaisePropertyChanged(propertyName);
return true;
}