2021-12-05

How to use ImageSource in xaml

I want to give the Button an Image like this:

<Button Name="Close" Grid.Column="1" HorizontalAlignment="Left" Margin="513,0,0,0" VerticalAlignment="Center" Height="15" Width="15" BorderBrush="{x:Null}" Click="Minimize_Click">
     <Button.Background>
         <ImageBrush ImageSource="{DynamicResource  CloseImage}"/>
     </Button.Background>
</Button>

and this is in my ResourceDictionary:

<ImageSource  x:Key="CloseImage"><Image Source="../Resource/close-button.png"></Image></ImageSource>

But it says that I can't add somethin in ImageSource (In German):

  Resources.xaml(7, 39): [MC3028] Einem Objekt vom Typ "System.Windows.Media.ImageSource" kann kein Inhalt hinzugefĆ¼gt werden. Zeile 7 Position 39.

I have no idea how to make this because this also doesn't work:

<Button Name="Close" Grid.Column="1" HorizontalAlignment="Left" Margin="549,0,0,0" VerticalAlignment="Center" Height="14" Width="14" BorderBrush="{x:Null}" Click="Close_Click" >
            <Button.Background>
                <ImageBrush ImageSource="../resource/close-button.png" TileMode="None"/>
            </Button.Background>
        </Button>

It says the recource can't be found.



from Recent Questions - Stack Overflow https://ift.tt/3plBT0g
https://ift.tt/eA8V8J

No comments:

Post a Comment