开发者

Why must I move a Popup outside of a control to have databinding work?

I have this XAML:

<ContentControl Micro:View.Model="{Binding ChildViewModel}">
    <Popup x:Name="TestPopup" Placement="Mouse" AllowsTransparency="True">
        <Border x:Name="border" Background="White" Padding="5" CornerRadius="10" BorderThickness="2" BorderBrush="Black" >
            <StackPanel Orientation="Vertical">
                <TextBlock x:Name="MainInfos" Text="{Binding MainInfos}" />
                <TextBlock x:Name="AltInfos" Text="{Binding AltInfos}" />
                <TextBlock x:Name="OtherInfos" Text="{Binding OtherInfos}" />
                <TextBlock x:Name="CanNotUseFieldInfos" Foreground="Red" Text="{Binding CanNotUseFieldInfos}" />
            </StackPanel>
        </Border>
    </Popup>
</ContentControl>

When I update the values of the properties of the datacontext, the textblocks are not updated.

If I move Popup outside of ContentControl like so:

<Popup x:Name="TestPopup" Placement="Mouse" AllowsTransparency="True">
    <Border x:Name="border" Background="White" Padding="5" CornerRadius="10" BorderThickness="2" BorderBrush="Black" >
        <StackPanel Orientation="Vertical">
            <TextBlock x:Name="MainInfos" Text="{Binding MainInfos}" />
            <TextBlock x:Name="AltInfos" Text="{Binding AltInfos}" />
            <TextBlock x:Name="OtherInfos" Text="{Binding OtherInfos}" />
            <TextBlock x:Name="CanNotUseFieldInfos" Foreground="Red" Text="{Binding CanNotUseFieldInfos}" />
        </StackPanel>
    </Border>
</Popup>

<ContentControl Micro:View.Model="{Binding ChildViewModel}"  PreviewMouseMove="Canvas_PreviewMouseMove" MouseEnter="myCanvas_MouseEnter" MouseLeave="myCanvas_MouseLe开发者_开发百科ave" d:LayoutOverrides="Width, Margin" />

It works.

Could someone explain me why? Is it possible to make the first XAML work?

Thanks in advance


Cannot reproduce any weird behavior from just wrapping a Popup in a ContentControl, i suspect the Micro:View.Model attached property changes the DataContext of the ContentControl.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜