为什么某些模板绑定值未显示在设计器中,而其他值却显示?[带有复制代码]
本文关键字:显示 其他 复制 代码 绑定 为什么 | 更新日期: 2023-09-27 18:37:22
我有一个奇怪的情况:以下示例代码替换了窗口的内容,使用资源库的背景色,并提供具有两个标签的堆栈面板。一个用于背景,一个用于标题。
问题是,他们在设计时 但是,<Label Content="{TemplateBinding Background}" />
确实完美地显示了背景值 <Label Content="{TemplateBinding Title}" />
仅在运行应用程序时执行此操作。这里有什么区别?
我已经尝试了TargetType(通过将其设置为MainWindow,没有效果)
这是完整示例:
<Window x:Class="TBinding.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Height="350" Width="525">
<Window.Style>
<Style TargetType="Window">
<Setter Property="Background" Value="LawnGreen" />
<Setter Property="Title" Value="The title of this window" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Window">
<StackPanel Margin="50" Background="{TemplateBinding Background}">
<Label Content="{TemplateBinding Background}" />
<Label Content="{TemplateBinding Title}" />
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Style>
</Window>
在连接上找到:https://connect.microsoft.com/VisualStudio/feedback/details/770067/wpf-designer-not-sho
设计器为窗口类而不是窗口本身创建代理。替代品不能完全反映所有属性,因此功能有限。
此问题在 VS2012 中以及 VS2013 中也会出现。