gpt4 book ai didi

wpf - StackPanel 在 MVVM 中的可见性

转载 作者:行者123 更新时间:2023-12-03 10:57:38 28 4
gpt4 key购买 nike

I'm working with WPF using Prism ( MVVM). I wanted to set visibililty of StackPanel from ViewModel calss. The StackPanel's visibility is binded like :


 <StackPanel x:Name="spVisibility"  Orientation="Horizontal" 
Visibility="{Binding spVisibility, Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}">

I've view model class like :


  public class SearchId : BindableBase, INotifyPropertyChanged
{
private Visibility _visibility = Visibility.Collapsed;

private DelegateCommand<object> searchCommand;

public event PropertyChangedEventHandler PropertyChanged;

public SearchId()
{
searchCommand = new DelegateCommand<object>(this.SearchData);
}///

public Visibility spVisibility
{
get { return _visibility; }
set
{
if (!string.Equals(_visibility, value))
{
_visibility = value;
RaisePropertyChanged("spVisibility");
}
}
}

private void RaisePropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this,
new PropertyChangedEventArgs (propertyName));
}

}

private async void SearchData(object parameter)
{
_visibility = Visibility.Visible;
}
}

But this not working. Please help me.

最佳答案

_visibility = Visibility.Visible正在设置私有(private)属性而不是使用公共(public)属性,所以 RaisePropertyChanged("spVisibility")正在被绕过。您需要使用 spVisibility = Visibility.Visible .

关于wpf - StackPanel 在 MVVM 中的可见性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39883501/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com