だから私は次のようなコードを持っています:(タイプミスを許してください-私は投稿のSOエディターで単純化しようとしました)
<my:CustomContentControl>
<my:CustomContentControl.Style>
<Style TargetType="{x:Type my:CustomContentControl}">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=CurrentView}" Value="MyCustomView">
<Setter Property="Content">
<Setter.Value>
<my:CustomView DataContext="{Binding DataContextForMyCustomView"/>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</m:CustomContentControl.Style>
</my:CustomContentControl>
問題は、発生するたびDataTrigger
に、セッターがContent
プロパティをに設定しますがmy:CustomView
、バインドしないDataContext
ことです。同じコードをトリガーの外に移動すると、DataContext
バインディングは問題なく機能します。
何か案は?これがある種の制限である場合、回避策はありますか?
アップデート:
出力ウィンドウで次のエラーを受け取りました。
System.Windows.Data Error: 3 : Cannot find element that provides DataContext. BindingExpression:Path=DataContextForMyCustomView; DataItem=null; target element is 'CustomView' (Name='customView'); target property is 'DataContext' (type 'Object')