Quantcast
Viewing all articles
Browse latest Browse all 1458

content for RibbonButton

Hello,

I have a suggestion for all rubbon classes that currently use ImageSource to show an icon. In many cases I prefer to use visual elements, like Path, to make a button icon. It's faster to define and more flexible than images. I can not do it for the RibbonButton because it has no Content property, and its control template includes only the Image element. I made a workaround, changing the RibbonButton templates to show a ContentControl which is binded to Tag property (can be an attached property):

<!-- Old template --> 
<Image
	x:Name="Image" 
	Margin="1" 
	VerticalAlignment="Center" 
	Stretch="Uniform" 
	Width="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ImageSourceSmallSize.Width}" 
	Height="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ImageSourceSmallSize.Height}" 
	Source="{TemplateBinding ImageSourceSmall}" 
	SnapsToDevicePixels="True" />
<!-- New template -->
<Viewbox x:Name="Image" Margin="1" 
	VerticalAlignment="Center" 
	Stretch="Uniform" 
	Width="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ImageSourceSmallSize.Width}" 
	Height="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ImageSourceSmallSize.Height}" 
	SnapsToDevicePixels="True" > <ContentPresenter Content="{TemplateBinding Tag}"/></Viewbox> 

 

Then I assign visual element that draws an icon to the Tag property in my XAML files . It works, but having a dedicated Content property would be better (it allows to use images as well).  

However, I've got a unexpected problem in my workaround. When any RibbonButton with 'Tag icon' is send to QAT (via a content menu), its icon on the button itself vanishes. Thus, the icon is copied to QAT but erased on the button in the ribbon tab. To get back the icon, I need to remove button from QAT and restart an application. I guess, it's related to control cloning for QAT.

Is there a fast solution for this problem?

Thanks in advance!

Ilia

 

 

 

 


Viewing all articles
Browse latest Browse all 1458

Trending Articles