TemplateBinding自定义窗口模板WPF中的标题 [英] TemplateBinding a Title in custom window template WPF
本文介绍了TemplateBinding自定义窗口模板WPF中的标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
因此,我正在为WPF应用程序制作自定义窗口模板.我遇到的麻烦是无法访问模板内的窗口标题"属性.
So I'm making a custom window template for my WPF application. The trouble I'm having is that I cannot access the Window Title property inside the template.
我尝试过:
<TextBlock Text="{TemplateBinding Title}" />
这:
<TextBlock Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Title}" />
我读过的所有内容都表明这两个中的任何一个都可以工作,但文本从未设置过.
Everything that I've read indicates that either of those two should work and yet the text is never set.
有什么建议吗?
显示整个样式xaml
Presenting the entire style 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>
推荐答案
因此,事实证明Expression Blend无法正确呈现窗口.一旦我运行代码,它就会真正起作用.我最不信任Expression Blend.
So it turns out that Expression Blend fails to render the window correctly. As soon as I run the code it actually works. My bad for trusting Expression Blend.
这篇关于TemplateBinding自定义窗口模板WPF中的标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文