同じウィンドウ内のListViewから選択されたアイテムがないときに非表示にしたいStackPanelがあります。現在、ウィンドウを開くと、選択されたアイテムがなく、StackPanelは非表示になっていますが、ListViewから何かを選択すると変更は発生しません。NullToVisibilityConverterが選択変更によってトリガーされない
私は次のようにリストビューでのSelectedItemを結合しています:
「SelectedIssueは」私のViewModelでのカスタムクラスのプロパティである<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">
(私の全体のウィンドウは同じのDataContextを持っています)。私は現在としての私のStackPanelのVisibilityプロパティをバインドしています:
<StackPanel
Grid.Column="1"
Margin="13,0,0,5"
VerticalAlignment="Bottom"
Background="#ebf7f6"
Orientation="Horizontal"
Visibility="{Binding SelectedIssue,
Converter={StaticResource NullToVisibilityConverter},
UpdateSourceTrigger=PropertyChanged}">
そして、私のコンバータは、次のとおりです。
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();
}
}
私は何をしないのですか?
EDIT:どうやら問題は、あなたがINotifyPropertyChanged
を実装していないか、(SelectedIssueのプロパティのセッターで)PropertyChanged
イベントを発生させないということである。ここに私の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;
}
あなたはSelectedIssueのgetter/setterメソッドを表示することができますか?おそらく、SelectedIssueが変更されたときのプロパティ変更イベントがありません。あなたがそれを教えない限り、UIは値が変更されたことを知らないでしょう... – CodexNZ
ちょうど追加されました。私はイベントを起こしていますよね? –
バインディングが有効になると、Visual Studioの出力ウィンドウにバインディングエラーが表示されますか?時々彼らは見逃しやすい。 –