c# - 为什么有些 TemplateBinding 值没有显示在设计器中,而其他的却显示了? [带复制代码]

标签 c# wpf xaml

我有一个奇怪的情况: 以下示例代码替换了窗口的内容,使用了 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/

相关文章:

c# - 如何在 C# 中使用 net stop 命令启动/停止服务

c# - 如何删除父控件

c# - XAML 分组的 GridView/语义缩放不显示所有子项?

c# - 具有透明填充但实线描边的 WPF 形状可能吗?

visual-studio-2010 - 我可以在 Visual Studio 中将设计 Pane 与 XAML Pane 分开吗?

c# - NUnit Assert.AreEqual 日期时间公差

c# - 为每个线程分配一个cpu核心

wpf - 如何使WPF Datagrid列不可聚焦?

Find() 的 Javascript 代码优化

c# - 从后面的代码设置 TextBox 的字体