How to Describe WindowCloseButton with Image in ResourceDictionary File in WPF Project

129 Views Asked by At

[It is solved]

I am developing a WPF project. I want to custom header for window. I created a Resource Dictionary. But I can not add image with path to resource dictionary. Some errors are occured. Follow I want to header that in picture enter image description here

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero" >
<!--Strat of my defined codes -->

<Image x:Key="WindowCloseImg" Source="..\Images\Windows\window_kapat.png"/>
<Style  x:Key="WindowCloseButtonStyle" TargetType="{x:Type Button}">
    <Setter Property="Content" Value="{DynamicResource WindowCloseImg}"/>
</Style>

<!-- Modal Window style -->
<Style x:Key="LoginWindowStyle" TargetType="{x:Type Window}">
    <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.WindowTextBrushKey}}"/>
    <Setter Property="WindowStyle" Value="None"/>
    <Setter Property="AllowsTransparency" Value="True"/>
    <Setter Property="Background" Value="Transparent"/>
    <Setter Property="Template" >
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Window}">
                <Border Background="{TemplateBinding Background}"  BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="20"/>
                            <RowDefinition Height="*"/>
                        </Grid.RowDefinitions>

                        <!-- Header -->
                        <Border Grid.Row="0" x:Name="Header" BorderBrush="Transparent" Background="{DynamicResource BackgroundBrush}" BorderThickness="1,1,1,0" CornerRadius="5,5,0,0">
                            <Grid>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition Width="*"/>
                                    <ColumnDefinition Width="20"/>
                                </Grid.ColumnDefinitions>
                                <Button BorderBrush="Transparent" Style="{StaticResource WindowCloseButtonStyle}" Grid.Column="2" Width="15" Height="15"  x:Name="btnClose" Command="Close"/>

                            </Grid>
                        </Border>

Project tree is followed picture :

enter image description here

How can I proceed?

I have solved problem. I changed StaticResources attibute to DynamicResources. After that it works!

0

There are 0 best solutions below