Solved

How to: WPF button with vector graphic

Posted on 2009-03-30
6
1,463 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
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…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

813 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

16 Experts available now in Live!

Get 1:1 Help Now