开发者

DataContext Inheritance in Behavior

开发者 https://www.devze.com 2023-04-06 07:31 出处:网络
I have 3 DependencyProperties declared in code behind of the MainWindow. The following code snippet is in the xaml code of the MainWindow:

I have 3 DependencyProperties declared in code behind of the MainWindow. The following code snippet is in the xaml code of the MainWindow:

<TextBlock>
    <e:Interaction.Behaviors>
        <bhv:VisibilityBehaviour>
            <mat:Matcher Value1="{Binding BOOL1}"/>
            <mat:Matcher Value1="{Binding BOOL2}"/>
            <mat:Matcher Value1="{Binding BOOL3}"/>
        </bhv:VisibilityBehaviour>
    </e:Interaction.Behaviors>
</TextBlock>

These Binding don't work. I think it's because the Behavior doesn't inherit the DataContext from parent Control. I know that when I use Freezable the DataContex开发者_如何学Ct is inherited but it doesn't work.

System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=BOOL1; DataItem=null; target element is 'Matcher' (HashCode=59587750); target property is 'Value1' (type 'Boolean')

Why isn't the DataContext inherited?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号