为什么我的功能区按钮图标不显示?

Why isn't my ribbon button icon showing?

我在 Modify 选项卡下的 Properties 选项卡下创建了一个要添加到 Revit 功能区的按钮。该按钮出现并正常运行。我们遇到的唯一问题是按钮的图标不会显示。我们已经尝试了多种方法来解决这个问题,但似乎没有任何效果。

代码:

Autodesk.Windows.RibbonControl pRibbon = Autodesk.Windows.ComponentManager.Ribbon;
foreach (var pTab in pRibbon.Tabs)
{
    if (pTab.Id == "Modify")
    {
        foreach (var pPanel in pTab.Panels)
        {
            if (pPanel.Source.Id == "properties_shr")
            {
                // Add button.
                pIcon = Properties.Resources.AS_Revit_UI_Taps_Tees32x32.GetHbitmap();
                var pBtn = CreatePanelButton(pIcon, "Taps/Tees", "id_astapteebutton", "Taps/Tees", 32, 32);

                Autodesk.Windows.ComponentManager.UIElementActivated += RunSwitchTapTee;
                pPanel.Source.Items.Add(pBtn);
                break;
            }
        }
    }
}

public Autodesk.Windows.RibbonButton CreatePanelButton(IntPtr pIcon, string sBtnName, string sID, string sText, int iHeight, int iWidth)
{
    var pBtn = new Autodesk.Windows.RibbonButton()
    {
        Name = sBtnName,
        Image = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(pIcon, IntPtr.Zero, System.Windows.Int32Rect.Empty, BitmapSizeOptions.FromWidthAndHeight(32, 32)),
        Id = sID,
        AllowInStatusBar = true,
        AllowInToolBar = true,
        GroupLocation = Autodesk.Private.Windows.RibbonItemGroupLocation.Middle,
        MinHeight = 0,
        MinWidth = 0,
        Height = iHeight,
        Width = iWidth,
        IsEnabled = true,
        IsVisible = true,
        IsCheckable = true,
        ShowImage = true,
        ShowText = true,
        Orientation = System.Windows.Controls.Orientation.Vertical,
        Text = sText,
        Size = Autodesk.Windows.RibbonItemSize.Large,
        ResizeStyle = Autodesk.Windows.RibbonItemResizeStyles.HideText
    };

    return pBtn;
}

结果是这样的:

如您所见,按钮已放置。它按预期工作。它只是不会显示图标...任何帮助将不胜感激。谢谢

我发现我的错误是在 Image 的设置上。我写道:

Image = System.Windows.Interop....
.
.
.
Size = Autodesk.Windows.RibbonItemSize.Large,

我需要调整一个或另一个 - ImageLargeImage RibbonItemSize.LargeRibbonItemSize.Standard.. .

只有大图片需要大尺寸,标准图片需要标准尺寸才有意义。

有什么区别?

在 Revit 中,功能区按钮可以是 16x16 像素(标准)或 32x32 像素(大)。根据您想要的 UI 布局将帮助您决定您需要哪个。