我有这个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>
当我更新datacontext的属性值时,文本块不会更新。
如果我像这样在ContentControl之外移动Popup:
<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_MouseLeave" d:LayoutOverrides="Width, Margin" />
有效。
有人可以解释我为什么吗?是否可以使第一个XAML工作?
提前致谢
答案 0 :(得分:1)
不能通过在ContentControl中包装Popup来重现任何奇怪的行为,我怀疑Micro:View.Model
附加属性会更改ContentControl的DataContext。