【发布时间】:2014-04-06 06:46:01
【问题描述】:
我正在尝试创建一个充当 IP 地址持有者的用户控件。 通常,该控件由 4 个 TextBoxes 组成,它们一起具有完整的 IP 地址。 在后面的用户控制代码中有一个公共属性,它保存 IPAddress 类型的 IP 地址。 我一直在尝试公开此属性,以便可以将 ViewModel 中的属性绑定到它。
这是我要公开的用户控件的属性:
public IPAddress IPAddressObject
{
get
{
return new IPAddress(m_IPAddress);
}
set
{
m_IPAddress = value.GetAddressBytes();
NotifyPropertyChanged("Octet1");
NotifyPropertyChanged("Octet2");
NotifyPropertyChanged("Octet3");
NotifyPropertyChanged("Octet4");
}
}
它的值得到正确更新,但我无法使用绑定将值放入我的 ViewModel 变量中。 我知道我需要以某种方式使用依赖属性,但我不知道如何将其值与我的属性联系起来。
谢谢你:)
【问题讨论】:
标签: wpf binding user-controls textbox ip-address