locked
Store Canvas and Path elements inside resources RRS feed

  • Question

  • Hello,

    I have bunch of canvas and path type elements that I use in several places in my application.

    Basicly I put path or canvas inside Button element.
    Most of the times it looks like this:

                    <Button Name="btPrev" Style="{StaticResource DoubleButtonStyleLeft}" Click="btPrev_Click" IsEnabled="False" Visibility="{Binding Path=IsNavigationVisible}">                   
    						<Canvas Width="10" Height="9" Margin="4,0,0,0">
    							<Path Fill="#FF343536" Stretch="Fill" Width="10" Height="9" Canvas.Left="0" Canvas.Top="0" Data="F1M9.9999,471L-9.99999999997669E-05,475.485L9.9999,480z"/>
    						</Canvas>					
                    </Button>
    

    I was wondering, how would it be possible to store <Canvas> and <Path> elements inside resource dictionary?
    My goal is to make <Button> element code as short as possible
    Tuesday, April 14, 2009 3:16 PM

Answers

  • Hi Daniil,

    you can define the Canvas in the Resources as well.

    <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    	Title="Window1" Height="300" Width="300">
    	
    	<Window.Resources>
    		<Canvas x:Key="buttonCanvas" Width="10" Height="9" Margin="4,0,0,0">
    			<Path Fill="#FF343536" Stretch="Fill" Width="10" Height="9" Canvas.Left="0" Canvas.Top="0" Data="F1M9.9999,471L-9.99999999997669E-05,475.485L9.9999,480z"/>
    		</Canvas>	
    	</Window.Resources>
    	
    	<Button Name="btPrev" IsEnabled="False" Content="{StaticResource buttonCanvas}" />
    
    </Window>
    Hope that helps.
    • Marked as answer by Daniil Harik Tuesday, April 14, 2009 8:07 PM
    Tuesday, April 14, 2009 7:55 PM

All replies

  • Hi Daniil,

    you can define the Canvas in the Resources as well.

    <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    	Title="Window1" Height="300" Width="300">
    	
    	<Window.Resources>
    		<Canvas x:Key="buttonCanvas" Width="10" Height="9" Margin="4,0,0,0">
    			<Path Fill="#FF343536" Stretch="Fill" Width="10" Height="9" Canvas.Left="0" Canvas.Top="0" Data="F1M9.9999,471L-9.99999999997669E-05,475.485L9.9999,480z"/>
    		</Canvas>	
    	</Window.Resources>
    	
    	<Button Name="btPrev" IsEnabled="False" Content="{StaticResource buttonCanvas}" />
    
    </Window>
    Hope that helps.
    • Marked as answer by Daniil Harik Tuesday, April 14, 2009 8:07 PM
    Tuesday, April 14, 2009 7:55 PM
  • Hello,

    Damn the solution is so simple. I should have though of it myself.

    Thank You very much.
    Tuesday, April 14, 2009 8:07 PM