Click here to Skip to main content
15,892,480 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI Code Projectees,
I'm new to WPF and here is my issue, I want to set the image in a button so can anyone tell how could i set the image path using XAML code..I knew how to make that in C# code..I think my queries are OK..




Thanks in advance,
JnFred
Posted

1 solution

You just need to use the image as the content for the button, something like this

XML
<Button Grid.Row="2">
            <Button.Content>
                <Image Source="your image file path"/>
            </Button.Content>
        </Button>


[Edit]

With regard to your comment, the only way I know how to do that is to include the image in your application(right click your project, then select add exiting file, and select your image), and then set the image file's Build Action to content. Then you can use a relative address for the image like this

XML
<Button Grid.Row="2">
            <Button.Content>
                <Image Source="image.jpg"/>
            </Button.Content>
        </Button>


[/Edit]

Hope this helps
 
Share this answer
 
v2
Comments
JnFred 26-Aug-11 6:57am    
Hi Wayne, actually I need like Application.Startup..
Wayne Gaylard 26-Aug-11 7:02am    
Sorry, I do not get what you mean.
JnFred 26-Aug-11 7:12am    
I mean i want to set the image path in my project 'debug' folder ..
For example, in C# we can use
string path=Application.StartUpPath;(window forms)
string path=AppPath.CurrentDomain.BaseDirectory;(WPF)

But here I want this in my XAML code...
Is that make sense now ??
Wayne Gaylard 26-Aug-11 7:38am    
See my updated answer.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900