0

我在询问 RibbonApplicationMenuItem 中的 16x16 像素图像被拉伸如何使功能区菜单项中的图像更小(而不是拉伸到 32x32,好像在任何情况下都是可取的)。

基于替换此类控件的控件模板,我得到了一个很好的答案,然后我开始认为我可以改用已经存在的模板并在 generic.xaml 中有设置器来修改其中的属性。

如何查看功能区控件具有哪些组件结构?通过右键单击属性“模板”并将控件模板提取到现有的 xaml 文件很容易完成。

我可以研究这样一个菜单项的整个组件结构。这里和那里,都有命名组件,我发现了一个名为“Image”的组件。

所以我尝试在 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>

但我得到的只是这个:

在此处输入图像描述

嗯,它产生了一些影响,但到底发生了什么?我做错什么了?我可以像这样调整控件的命名图像的大小吗?

4

2 回答 2

0

我从未尝试过使用 generic.xaml 中的主题进行类似的操作,但您可以创建一个新文件并创建一个新的资源字典。现在插入您的样式并设置 x:Key 属性,如下所示:x:Key{x:Typeribbon:RibbonApplicationMenuItem}。现在转到您的 App.xaml,它应该看起来像这样

<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>
于 2012-08-10T13:30:58.963 回答
0

好的,这是我在研究时得到的:

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

正在设置 Image 的任何实例的高度,而不是名称为“Image”的控件。

并使用

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

不起作用,因为您不能在模板中使用 TargetName,除非它在触发器中。

于 2012-08-13T16:11:13.323 回答