Reputation: 1508
I have added a custom style for a window. However I can't get an image in the titlebar.
I have tried to make a image resource and set the static resource of the image to the image source like in this topic: WPF Setting Image.Source from DataTrigger (Answer from ExplodingRabbit)
What I want is to have an image in my project resource and add this resource to the source of the image in the titlebar. (In the code where it says IMAGE HERE!)
For the simplicity, I have only added the important piece of the style.
<Style x:Key="MainWindow"
TargetType="{x:Type Window}">
<Setter Property="Foreground"
Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Window}">
<Grid Background="{DynamicResource AchmeaGrey}">
........................
<Border x:Name="PART_TITLEBAR">
<Grid>
<IMAGE HERE!>
<TextBlock />
<DockPanel LastChildFill="False">
<Button />
<Button />
</DockPanel>
</Grid>
</Border>
........................
</Grid>
...................
Upvotes: 1
Views: 614
Reputation: 9713
You can create an ImageSource
resource in your window resources, or wherever you are creating the main window style:
<ImageSource x:Key="MyImage">pack://application:,,,/Images/image.jpg</ImageSource>
And in your ControlTemplate
, simply set the Source
property on the image to that of the ImageSource
key.
<Image Source="{DynamicResource MyImage}" ... />
Upvotes: 2