Solved

How to: WPF button with vector graphic

Posted on 2009-03-30
6
1,437 Views
Last Modified: 2013-11-12
Hi,
I would like to put a vector (xaml) graphic as the icon of a button in wpf.
Does anyone have any ideas?.
e.g. export a graphic from expression design, import into blend... but how then to get it onto the button?
0
Comment
Question by:quentinA
  • 3
  • 2
6 Comments
 
LVL 16

Expert Comment

by:TSmooth
ID: 24028201
Just put that xaml within the button's content tag.. it'd look something like:

<Button x:Name="MyButton">
  <Button.Content>
    <--Insert XAML for graphic here -->
  </Button.Content>
</Button>
0
 
LVL 8

Expert Comment

by:unmeshdave
ID: 24034524
if you are working with MS Expression Blend, Its very easy & Standard way to do it, just create a project as resource dictionary and create your graphics. Resource Dictionary will be xaml. so add that xaml into your project.
In your main window xaml,
do as attached code.
 

        <ResourceDictionary>

            <ResourceDictionary.MergedDictionaries>

                <ResourceDictionary Source="" /> <!--in double quotes write your xaml path -->

            </ResourceDictionary.MergedDictionaries>

        </ResourceDictionary>
 

<!-- In your Button code do following where graphicsKey is the key which is defined in your graphics xaml for your grphics-->

<!-- Here, you can also set background property as graphics if you want instead of content -->

<Button x:Name="MyButton" Content="{StaticResource graphicsKey}" />

Open in new window

0
 
LVL 8

Expert Comment

by:unmeshdave
ID: 24034541
More Easy way is (not always possible), just open your WPF project in Blend , you will see your button. create graphics on button. save project. you are all set. you can run it from VS or Blend itself.
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:quentinA
ID: 24040385
Dear unmeshdave:

I coming from a really low baseline... would you mind giving me a bit more detail about how to save the graphic as a resource dictionary in one project and then use it in another project.

0
 
LVL 8

Accepted Solution

by:
unmeshdave earned 500 total points
ID: 24042982
well you can start a new project in Blend 2. then From file menu, add new item, it will ask you type of item. select resourcedictionary. Moreover, you can design the graphics in your window1, go to window1.xaml and copy the code between window tag and paste it into resourcedictionry xaml between resourcedictionary tags. then u can use that xaml file into your project as I mentioned in above code.
But real easier way is as I told, open your project in Blend. draw graphics on Button as you want in Blend. save project. you can run project Blend as well. or go back to VS and open the project and run it.
0
 

Author Closing Comment

by:quentinA
ID: 31564543
I copied the resourcedictionary reference code at the app.xaml level and it worked. The reason that I wanted this solution was because I might want to re-use the same graphic in mutliple locations. Many thanks.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now