Solved

How to: WPF button with vector graphic

Posted on 2009-03-30
6
1,486 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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 

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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Visual studio 2015 1 34
VS 2017 18 101
Consume a webservice via VB in Visual Studio 2015 3 14
Vb.net progressbar with timer1 in visual studio win app 11 34
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

713 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