【问题标题】:TemplateBinding a Title in custom window template WPFTemplateBinding 在自定义窗口模板 WPF 中的标题
【发布时间】:2011-03-08 23:25:19
【问题描述】:

所以我正在为我的 WPF 应用程序制作一个自定义窗口模板。我遇到的问题是我无法访问模板内的 Window Title 属性。

我试过这个:

<TextBlock Text="{TemplateBinding Title}" />

还有这个:

<TextBlock Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Title}" />

我读过的所有内容都表明这两者中的任何一个都应该可以工作,但文本从未设置过。

有什么建议吗?

编辑:呈现整个样式 xaml

<Style x:Key="RegularWindow" TargetType="{x:Type Window}">
    <Setter Property="Foreground" Value="{StaticResource {x:Static SystemColors.WindowTextBrushKey}}"/>
    <Setter Property="Background" Value="Transparent"/>
    <Setter Property="AllowsTransparency" Value="True"/>
    <Setter Property="WindowStyle" Value="None"/>
    <Setter Property="SizeToContent" Value="WidthAndHeight"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Window}">
                <Border BorderBrush="{TemplateBinding BorderBrush}" CornerRadius="10" Background="{TemplateBinding Background}">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>
                        <TextBlock Text="{TemplateBinding Title}" FontWeight="Bold" Grid.Row="0" />
                        <AdornerDecorator Grid.Row="1">
                            <ContentPresenter/>
                        </AdornerDecorator>
                    </Grid>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

【问题讨论】:

  • 可以分享一下xaml模板代码吗?

标签: wpf binding window title


【解决方案1】:

结果是 Expression Blend 无法正确渲染窗口。一旦我运行代码,它就会真正起作用。我不信任 Expression Blend。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多