文字列依存関係プロパティとしてLocalIPPropertyという依存関係プロパティを作成しました。すべて問題ありませんが、後でアプリケーションでUserControlを使用し、VSプロパティウィンドウでそのLocalIPPropertyを非IPテキストに変更すると、VSプロパティウィンドウにデフォルトのIP文字列(127.0.0.1)が表示され、XAMLでは:LocalIP=が追加されます。 「sdahashfah」とすると、アプリケーションを実行しようとすると、XalmParserExceptionが発生します。
また、LocalIPPropertyをIPAddress Dependencyプロパティとして作成しようとしましたが、UserControlを使用したアプリケーションでは、IPAddressを変更しませんでした。
必要なのは、VSプロパティウィンドウでLocalIPを非IP文字列に設定しても、値は変更されないままであるということです。
私が今持っているのは:
public static DependencyProperty LocalIPProperty = DependencyProperty.
Register("LocalIP", typeof(string), typeof(UserControl1),
new FrameworkPropertyMetadata("127.0.0.1"), IPPropertyValidate);
private static bool IPPropertyValidate(object value)
{
try
{
IPAddress.Parse((string)value);
}
catch { return false; }
return true;
}
[Description("IP for listening."), Category("Address")]
public string LocalIP
{
get { return (string)GetValue(LocalIPProperty); }
set { SetValue(LocalIPProperty, value); }
}
努力してくれてありがとう。