Reputation: 537
Theme/Generic.xaml of my WPF Custom Control MyBaseWindow looks like this:
<Style TargetType="{x:Type MyBaseWindowPath:MyBaseWindow}">
…
<Setter Property="WindowChrome.WindowChrome">
<Setter.Value>
<WindowChrome CaptionHeight="{Binding ActualHeight, ElementName=HeaderPanel}"
GlassFrameThickness="0"
CornerRadius="0" />
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type MyBaseWindowPath:MyBaseWindow}">
…
<DockPanel x:Name="HeaderPanel">
…
</DockPanel>
…
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
I would like to bind ActualHeight
property of HeaderPanel element within ControlTemplate
. Is it possible?
Another solution is use fixed height for WindowChrome.CaptionHeight
and HeaderPanel.Height
, but I prefer binding to exact height.
Upvotes: 1
Views: 1647
Reputation: 1
In 2021, my solution without binding was to assign a x:Name to the WindowChrome and change CaptionHeight
value in Window_SizeChanged
event:
private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
{
SessionWindowChrome.CaptionHeight = ActualHeight
- SessionWindowChrome.ResizeBorderThickness.Top
- SessionWindowChrome.ResizeBorderThickness.Bottom;
}
Take in account that i use ResizeBorderThickness
variables too...
Upvotes: 0
Reputation: 11463
ActualHeight
is not a DependencyProperty
or an INotifyPropertyChanged
, so you can't bind directly to it and expect more than a one-time read. You can set a trigger on it in a style.
Work-around includes:
DependencyProperty
or an INotifyPropertyChanged
property.SizeChanged
event on the element you want to know the AbsoluteHeight
on.A fancier implementation would use attached dependency properties that essentially do the same thing, but they would be a bit more general purpose.
Upvotes: 1