XAML image assets and C1MenuItems

Posted by: marc.brown on 29 November 2017, 5:11 am EST

    • Post Options:
    • Link

    Posted 29 November 2017, 5:11 am EST

    I have some images defined in my WPF project’s App.xaml like this:

    		<ControlTemplate x:Key="Open_32x">
    			<Viewbox Width="32" Height="32" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
    				<Rectangle Width="32" Height="32">
    					<Rectangle.Fill>
    						<DrawingBrush>
    							<DrawingBrush.Drawing>
    								<DrawingGroup>
    									<DrawingGroup.Children>
    										<GeometryDrawing Brush="#FFF6F6F6" Geometry="F1M22.8711,21L32.0001,11.828 32.0001,10.172 22.8711,1 11.2151,1 17.2151,7 12.0431,7C5.4261,7 0.043099999999999,12.383 0.043099999999999,19 0.043099999999999,25.617 5.4261,31 12.0431,31L14.0001,31 14.0001,23 12.0431,23C9.8381,23 8.0431,21.207 8.0431,19 8.0431,16.793 9.8381,15 12.0431,15L17.2151,15 11.2151,21z" />
    										<GeometryDrawing Brush="#FF00529C" Geometry="F1M22.043,3L16.043,3 22.043,9 12.043,9C6.52,9 2.022,13.477 2.022,19 2.022,24.523 7,29 12,29L12,25C9,25 6.022,22.313 6.022,19 6.022,15.686 8.729,13 12.043,13L22.043,13 16.043,19 22.043,19 30.043,11z" />
    									</DrawingGroup.Children>
    								</DrawingGroup>
    							</DrawingBrush.Drawing>
    						</DrawingBrush>
    					</Rectangle.Fill>
    				</Rectangle>
    			</Viewbox>
    		</ControlTemplate>
    
    

    I’m using them with toolbar buttons like this:

    			<c1:C1ToolbarButton x:Uid="OpenFile" Margin="2" Click="OnToolbarButtonClick" ToolTip="Open a file">
    				<ContentControl Template="{StaticResource Open_32x}"/>
    			</c1:C1ToolbarButton>
    
    

    I would like to use these for my C1MenuItems as well; however, I don’t know how to do so. Setting the Icon property to {StaticResource (or DynamicResource) Open_32x} doesn’t work because they’re not seen as images by the class.

    Is it possible to do what I want? If so, can you give me a pointer?

    Thanks, Marc

  • Posted 29 November 2017, 3:56 pm EST

    Hi,

    Please try to use as below.

         ```
       <c1:C1MenuItem Click="OnMenuItemClick">
                    <c1:C1MenuItem.HeaderTemplate>                        
                        <ItemContainerTemplate>
                            <ContentControl Template="{StaticResource Open_32x}"></ContentControl>                        
                        </ItemContainerTemplate>
                    </c1:C1MenuItem.HeaderTemplate>                    
                </c1:C1MenuItem>
    
    
    Hope, it will solve your issue.
    
    Thanks,
    Singh
  • Posted 30 November 2017, 1:31 am EST

    That solution displays the image in the area of the menu that you’d expect to see text in rather than in the “gutter” where you’d expect to see an icon (see attached image).

  • Posted 30 November 2017, 1:32 am EST



    Sorry, the image didn’t attach the first time.

  • Posted 30 November 2017, 3:20 pm EST

    Hi,

    Try to use below suggestion:

    
    <c1:C1MenuItem Header="Open" >
                                <c1:C1MenuItem.Icon>
                                    <ContentControl Template="{StaticResource Open_25x}">                                    
                                    </ContentControl>
                                </c1:C1MenuItem.Icon>
                            </c1:C1MenuItem>
    
    

    Note: Icon’s width should not be more than 25.

    If You want to display large icon then you need to edit its template stored at :

    C:\Program Files (x86)\ComponentOne\WPF Edition\C1WPF.4\XAML\C1Mnu.xaml

    Thanks,

    Singh

  • Posted 1 December 2017, 2:13 am EST

    Thanks so much! I thought I’d tried that before but obviously hadn’t. Works like a charm.

    –mab

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels