C# 弹出绑定未正确完成
我有一个listview,在鼠标进入某一列时,我尝试在viewmodel类中启动一个弹出窗口,方法是在MyAction2()函数中将isOpen设置为true,当用户在listview的该列上输入鼠标时,会调用该函数 我观察到,当鼠标进入该列时,它会调用我的函数(ViewModel中的MyAction2()函数,请参阅下面编写的代码),但即使在MyAction2()中将isopen变量设置为true,也不会调用绑定的isopen的set get方法。现在我觉得装订有问题。这通常应该是正确的,我觉得有些东西丢失了,但我不知道是什么 我的Xaml(包含opup和ListView中的列,在ViewModel中,该列在鼠标输入时调用名为MyAction2()的事件):C# 弹出绑定未正确完成,c#,wpf,mvvm,binding,popup,C#,Wpf,Mvvm,Binding,Popup,我有一个listview,在鼠标进入某一列时,我尝试在viewmodel类中启动一个弹出窗口,方法是在MyAction2()函数中将isOpen设置为true,当用户在listview的该列上输入鼠标时,会调用该函数 我观察到,当鼠标进入该列时,它会调用我的函数(ViewModel中的MyAction2()函数,请参阅下面编写的代码),但即使在MyAction2()中将isopen变量设置为true,也不会调用绑定的isopen的set get方法。现在我觉得装订有问题。这通常应该是正确的,我觉
什么错了,哪里错了?您应该设置popupLaunched属性,而不是设置popUpLaunched字段以调用setter并引发PropertyChanged事件:
private void MyAction2(object param)
{
PopUpLaunched = true;
}
为了实现这样的绑定,可以将该属性设置为如下所示的依赖属性
public static readonly DependencyProperty PopUpLaunched = DependencyProperty.Register(
"popUpLaunched", typeof(bool), typeof(MainPage), new PropertyMetadata(null));
public bool popUpLaunched
{
get { return (bool)GetValue(PopUpLaunched); }
set { SetValue(PopUpLaunched, value); }
}
如果不在主页上工作,请分别更改该typeof(MainPage)参数。并根据您的需要调整getter和setter。Ohh good。。为此浪费了3个小时:'(但通常我们会将值赋给私有变量,对吗?不,您应该始终设置PropertyChanged事件的属性,以便在希望视图中发生某些事情时引发。视图会侦听属性更改,它对字段一无所知。好的,非常感谢
private void MyAction2(object param)
{
PopUpLaunched = true;
}
public static readonly DependencyProperty PopUpLaunched = DependencyProperty.Register(
"popUpLaunched", typeof(bool), typeof(MainPage), new PropertyMetadata(null));
public bool popUpLaunched
{
get { return (bool)GetValue(PopUpLaunched); }
set { SetValue(PopUpLaunched, value); }
}