好的,这与以下问题有关:WPF从单个视图模型打印多个页面。
我试图按照那里给出的建议进行操作,但现在我卡住了。
我的应用程序使用MainView.xaml和相应的MainViewViewModel.cs,我在后台使用MVVM Light。
现在-根据帖子-似乎我必须执行以下操作:
我的用户控件(UcTest.xaml)公开了一个依赖属性:
我试图按照那里给出的建议进行操作,但现在我卡住了。
我的应用程序使用MainView.xaml和相应的MainViewViewModel.cs,我在后台使用MVVM Light。
现在-根据帖子-似乎我必须执行以下操作:
- 创建一个用户控件
- 从用户控件公开一些属性
- 确保视图模型显示这些属性
我的用户控件(UcTest.xaml)公开了一个依赖属性:
public string SpecialText
{
get { return (string)GetValue(SpecialTextProperty); }
set
{
SetValue(SpecialTextProperty, value);
}
}
// Using a DependencyProperty as the backing store for SpecialText. This enables animation, styling, binding, etc...
public static readonly DependencyProperty SpecialTextProperty =
DependencyProperty.Register("SpecialText", typeof(string), typeof(UcTest), new PropertyMetadata(new PropertyChangedCallback(SpecialTextChangedPropertyCallback)));
private static void SpecialTextChangedPropertyCallback(DependencyObject sender, DependencyPropertyChangedEventArgs e)
{
// Do something
Debug.WriteLine("Ffgdgf");
}
好的,现在我有一个用户控件,其中包含一些依赖属性。然而,这些属性与我的ViewModel属性完全分离(这些属性将被显示)。
所以基本上我有两种可能:
- 现在我如何告诉我的UserControl的ViewModel一些属性已经改变了?
- 是否有一种方法可以忘记依赖属性并直接访问ViewModel?
附加信息#1: 我上传了一个(简单的)示例,展示我想要做的事情:示例项目。我希望从MainViewViewModel更改UserControl1中标签的值(通过UserControl1的ViewModel的绑定属性)。