Question

I was asking in 16x16 pixel images in RibbonApplicationMenuItem gets stretched how to make images that are in ribbon menu items smaller (and not stretching out to 32x32 as if that in any case would be desirable).

I got an excellent answer, based on replacing the control template for such controls and then I started to think that I could instead use the already present templates and have setters in generic.xaml that modifies properties in them.

How to see which component structure a ribbon control has? It is easily done by right clicking the property "Template" and extract the control template to an existing xaml file.

I could investigate the whole component structure of such a menu item. Here and where, there are named components, and I found a component with the name "Image".

So I tried to do this in generic.xaml:

<Style TargetType="{x:Type ribbon:RibbonApplicationMenuItem}">
  <Setter Property="Image.Height" Value="16" />
  <Setter Property="Image.Width" Value="16" />
</Style>

<Style TargetType="{x:Type ribbon:RibbonApplicationSplitMenuItem}">
  <Setter Property="Image.Height" Value="16" />
  <Setter Property="Image.Width" Value="16" />
</Style>

but all I got was this:

enter image description here

Well, it had some effect, but what is really happening? What did I do wrong? Can I resize named images of a control like this?

Was it helpful?

Solution 2

ok, this is what I have got while researching:

<Setter Property="Image.Height" Value="16" />

is setting the height of any instance of Image, not the control with the Name "Image".

And using

<Setter TargetName="Image" Property="Height" Value="16" />

does not work because you cant use TargetName inside a template, unless its in a trigger.

OTHER TIPS

I ve never tried something like this with themes in generic.xaml but you can create a new file and create a new resourcedictionary. Now insert your styles and set the x:Key attribute like this: x:Key{x:Type ribbon:RibbonApplicationMenuItem}. Now go to your App.xaml and it should look like this

<Application x:Class="Coba.WPF.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"              
             StartupUri="MainPage.xaml">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>

                                   <ResourceDictionarySource="yourresourcedictionarypath.xaml" />

            </ResourceDictionary.MergedDictionaries>           
        </ResourceDictionary>
    </Application.Resources>
</Application>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top