Solved

How to: WPF button with vector graphic

Posted on 2009-03-30
6
1,503 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

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

DevOps Toolchain Recommendations

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

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
reading an excel file vb.net 2 47
SSIS Column mapping 5 42
Replace statements HTML with HTML IF 8 66
Adding Rows to Grid 4 33
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…
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…
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…

751 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