Krzysztof J. Obara
Krzysztof J. Obara

Reputation: 143

How to use XAML icons with Ribbon?

I have a Ribbon that is currently configured like this to show icons:

<Style x:Key="PrintMenuButton" TargetType="rib:RibbonApplicationSplitMenuItem">
    <Setter Property="ImageSource" Value="/styles/metro/print.png"/>
</Style>

I want to switch to XAML (or SVG) vector icons. I got Syncfusion Metro Studio that spits out icons in the following format:

<Viewbox xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
 <Grid>
  <Grid Name="backgroundGrid" Width="256" Height="256" Visibility="Collapsed" />
  <Path Data="M19.833,0L32.5,0 32.5,19.833999 52.334,19.833999 52.334,32.500999 32.5,32.500999 32.5,52.333 19.833,52.333 19.833,32.500999 0,32.500999 0,19.833999 19.833,19.833999z" Stretch="Uniform" Fill="#FF228B22" Width="138" Height="138" Margin="0,0,0,0" RenderTransformOrigin="0.5,0.5">
<Path.RenderTransform><TransformGroup>
<TransformGroup.Children>
<RotateTransform Angle="0" />
<ScaleTransform ScaleX="1" ScaleY="1" />
</TransformGroup.Children>
</TransformGroup>
</Path.RenderTransform>
</Path>
</Grid>
</Viewbox>

However, with my very limited skills in XAML I have a hard time mixing this together to work.

I put this icon (everything with Viewbox) inside ResourceDictionary and added x:Key="MyLovelyIcon", but it won't work and I am not sure why.

I would be grateful if someone could advise me how to glue those things together. Thank you.

Upvotes: 0

Views: 998

Answers (1)

Krzysztof J. Obara
Krzysztof J. Obara

Reputation: 143

After some poking around I got what I wanted:

<Style x:Key="PrintMenuButton" TargetType="rib:RibbonApplicationSplitMenuItem">
    <Setter Property="ImageSource" Value="{StaticResource XamlIcon_Misc_Print}"/>
</Style>

and

<DrawingImage x:Key="XamlIcon_Misc_Print">
    <DrawingImage.Drawing>
        <GeometryDrawing Brush="#FF000000" Geometry="M6.6669998,lots of digits"/>
    </DrawingImage.Drawing>
</DrawingImage>

So basically I did away with Path and moved the data to Geometry object. If someone would like to comment on when to use one and when the other and how they differ, or spare a link to MSDN, that would be great. Thanks.

Upvotes: 1

Related Questions