【发布时间】:2016-05-06 13:40:24
【问题描述】:
我有一个使用INotifyPropertyChanged 的类Device,它已经过测试并且可以工作。
现在我有一个deviceMonitor,它是这个设备的 UI 表示。在代码中我引用了Device,我想将设备中的更改链接到UI中的更改(不需要两种方式,但单击deviceMonitor应该调用device的某个函数)
我正在将表达式 Blend 与 VS2015 一起使用,因此非常欢迎基于单击以使其工作的位置的指导。
这是device的模型
public class Device : INotifyPropertyChanged
{
public string Name { ... } //uses NotifyPropertyChanged in the set
// other properties and their relative private vars.
}
然后是GUI的xaml.cs,这里我引用了包含Device的dll:
public partial class DeviceControl : UserControl
{
public Device myDevice = new Device();
public DeviceControl()
{
InitializeComponent();
// here I tried setting the datacontest to the myDevice
// also tried to set the dataContext in Blend and here grab a
// reference to it and store it in myDevice. But nothing workerd
}
public void ChangeDevName()
{
this.myDevice.DeviceName = "Test";
//UI Representation of deviceName never changed
}
}
然后是 XAML
<UserControl>
<UserControl.DataContext>
<recoveriX:RecoverixDevice DeviceName="thisIsAName"/>
</UserControl.DataContext>
<Grid>
<TextBlock x:Name="title" Text="{Binding DeviceName}"/>
</Grid>
</UserControl>
【问题讨论】:
标签: c# wpf data-binding blend