C# /// public void Execute(对象参数) { mAction(); } #端区 }
编辑:我正在使用FodyWeavers您就快到了:C# /// public void Execute(对象参数) { mAction(); } #端区 },c#,mvvm,treeview,fody,C#,Mvvm,Treeview,Fody,编辑:我正在使用FodyWeavers您就快到了: <TreeView ... Visibility="{Binding IsItemSelected}"> 支持字段不应为公共字段 您应该(通常)为绑定中使用的所有属性发出通知。通常在setter的末尾 我个人会使用getter-only属性: string _selectedItem; public string SelectedItem { get => _selectedItem; set {
<TreeView ... Visibility="{Binding IsItemSelected}">
支持字段不应为公共字段 您应该(通常)为绑定中使用的所有属性发出通知。通常在setter的末尾 我个人会使用getter-only属性:
string _selectedItem;
public string SelectedItem
{
get => _selectedItem;
set
{
_selectedItem = value;
OnPropertyChanged();
OnPropertyChanged(nameof(IsItemSelected));
}
}
public bool IsItemSelected => SelectedItem != null;
此外,您还缺少正确的事件上升方法:
public class BaseViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
// can be public if you want to rise event from outside
protected void OnPropertyChanged([CallerMemberName] string property = "") =>
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
}
当
ComboBox.SelectedItem==null
时,是否要隐藏TreeView
?这是一种可能的方法,但我更愿意根据ComboBox的选定项(directoryPath)生成TreeView,以便快速回答。我现在就去看看。也许我应该澄清一下,我使用的是FODYWEAVERS,这让我走上了正确的道路。非常感谢,先生D
public class BaseViewModel : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
// can be public if you want to rise event from outside
protected void OnPropertyChanged([CallerMemberName] string property = "") =>
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
}