jeudi 26 mars 2015

Set an image in an style template from resources

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>


...................


Aucun commentaire:

Enregistrer un commentaire