バインドの動作が異常です。DataContext
& IsEnabled
UserControlのプロパティ。私のページでStrange Behavior UserControlのDataContextおよびIsEnabled-Propertyをバインドします。
、私はこのようなユーザーコントロールを使用します。
<httpsPort:HttpsPort DataContext="{Binding Path=Https}"
IsEnabled="{Binding CurrentServiceState, Converter={StaticResource ServiceStateIsConfigableConverter}}" />
そして、このようなボタン:
<Button Content="start service"
IsEnabled="{Binding CurrentServiceState, Converter={StaticResource ServiceStateIsConfigableConverter}}"
Command="{Binding CmdConfigureService}" [...] />
説明:
コンバータはにcurrentServiceState-列挙型を変換し、ブール私のボタンは、期待通りに動作します(En/DisAbled)。
問題:マイボタンが正しく有効/無効になっていますが、私のユーザコントロールのコントロールは正しくありません。
のDataContext(HTTPS)は、実際にnullではない:
private HttpsPortViewModel _https;
public HttpsPortViewModel Https
{
get
{
if (_https == null)
{
_https = new HttpsPortViewModel();
}
return _https;
}
set
{
_https = value;
NotifyPropertyChanged(() => Https);
}
}
私はバインディング私のUserControlに偽FallbackValue =を使用しようとしましたが、その後、ユーザーコントロールも無効である...
誰も説明できますこれらの行動? ありがとうございました。
更新:
マイ対処方法:あなたがあなた自身のDataContext
結合するべきではありません
<Grid IsEnabled="{Binding CurrentServiceState, Converter={StaticResource ServiceStateIsConfigableConverter}}">
<httpsPort:HttpsPort DataContext="{Binding Path=Https}" />
</Grid>
あなたは実際に問題を述べたことはありません。そうしてください。 –
こんにちはダニエル、問題は、ユーザーコントロールがボタンのようにen/disabledされていないということです。 –
DataContextプロパティをバインドすることはお勧めできません。なぜあなたはusercontrolのためにそれをしますか?それはそれなしのボタンのために働くようです。 –