Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to: WPF button with vector graphic

Posted on 2009-03-30
6
Medium Priority
?
1,576 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 1500 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
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…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

721 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