Link to home
Start Free TrialLog in
Avatar of Matt Cartlidge
Matt CartlidgeFlag for United Kingdom of Great Britain and Northern Ireland

asked on

XAML: How to embed XAML geometry image in to a button

In WPF, I have many icons which I want to display within their own button using XAML. However, I want to use images which are purely XAML-based. These are basically converted from SVG.

I've been able to create my splash screen using XAML images by adding a DataTemplate and referring to it with a ContentPresenter in a Canvas and specifically adding the size and position by doing this.

                <Canvas Margin="25,40,0,0">
                    <ContentPresenter Width="175" x:Name="imagelogoplay" ContentTemplate="{StaticResource img-circled-play}"/>
                </Canvas>

Open in new window


I've been using the below code to create an image with an image inside.

        <StackPanel HorizontalAlignment="Right" VerticalAlignment="Center" Grid.Column="1">
            <Button Width="64" Height="64">
                <Canvas>
                    <ContentPresenter ContentTemplate="{StaticResource img-hand}"/>
                </Canvas>
            </Button>
        </StackPanel>

Open in new window


However, the image stays a static size no matter what values I use either in the canvas or the content presenter.

User generated image
I also thought about putting the canvas in to a viewbox. However, this makes the image disappear completely.

I'm pretty new to XAML so would appreciate if someone could shed light on this.

I've attached the icons.xaml file which I am using as a resource which contains the "img-hand" data template.
icons.xaml
ASKER CERTIFIED SOLUTION
Avatar of Snarf0001
Snarf0001
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Matt Cartlidge

ASKER

Thank you for your explanation. It is working great now.