【发布时间】:2018-05-02 07:17:57
【问题描述】:
我的 Page1.xaml.cs(代码隐藏)中有一个需要更改 ViewModel 中所有属性的事件。
这里是一个例子:(Page1.xaml.cs)
public Page1()
{
InitializeComponent();
example.Event += example_Event;
}
private void example_Event(...)
{
// here I want to change all Properties in my ViewModel
}
我怎样才能做到这一点?
编辑
我有一个显示 .ppt 的 WebBrowser-Control。我想在触发此事件时更新 ViewModel 中的所有属性:
xaml.cs:
private void powerPointBrowser1_LoadCompleted(object sender, NavigationEventArgs e)
{
//...
oPPApplication.SlideShowNextSlide += ppApp_SlideShowNextSlide; //Event that gets triggered when i change the Slide in my WebBrowser-Control
}
private void ppApp_SlideShowNextSlide(PPt.SlideShowWindow Wn)
{
// here i dont know how to get access to my Properties in my VM (i want to call OnChangedProperty(//for all properties in my VM))
}
【问题讨论】:
-
使用 null 或空属性名称触发视图模型的 PropertyChanged 事件。
-
是的,我知道我必须使用 string.empty ^^ 但我不知道如何在我的代码隐藏中触发 OnPropertyChanged 以获取我的 VM 中的属性。
-
我们也不知道,因为您没有向我们展示您的视图模型的相关部分。我会说,向调用 OnPropertyChanged 的视图模型添加一个公共方法。
-
提升datacontextchanged怎么样? msdn.microsoft.com/en-us/library/…
-
对我来说似乎是XY problem。您实际上想要达到什么目标?
标签: c# wpf inotifypropertychanged