我有一个奇怪的情况: 以下示例代码替换了窗口的内容,使用了 setter 的背景颜色并提供了一个带有两个标签的堆栈面板。一张用于背景,一张用于标题。
问题是,他们在设计时
<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
Designer 为 Window 类而不是 Window 本身创建代理。替代品不能完全反射(reflect)所有属性,因此功能有限。
VS2012 和 VS2013 中都会出现此问题。
关于c# - 为什么有些 TemplateBinding 值没有显示在设计器中,而其他的却显示了? [带复制代码],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19677680/