在RibbonQuickAccessToolBar

时间:2015-05-25 11:50:03

标签: c# wpf

在下面的代码中,'QuickToolBar.AddChild(SaveBtn)'行给出了以下错误:

  

System.Windows.Controls.ItemsControl.AddChild(object)无法访问   由于其保护水平。

我不明白此错误消息的原因。请帮忙

using System;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Controls.Ribbon;

namespace Ribbon3
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            CreateRibbon();
        }

        public void CreateRibbon()
        {
            Ribbon ribbon = new Ribbon();
            ribbon.SelectedIndex = 0;
            RibbonQuickAccessToolBar QuickToolBar = new RibbonQuickAccessToolBar();
            RibbonButton SaveBtn = new RibbonButton();
            QuickToolBar.AddChild(SaveBtn);

        }
    }
}

1 个答案:

答案 0 :(得分:3)

该方法受到保护:

https://msdn.microsoft.com/en-us/library/system.windows.controls.itemscontrol.addchild(v=vs.110).aspx

只有通过派生类类型进行访问时,才能在派生类中访问基类的受保护成员。

https://msdn.microsoft.com/en-us/library/bcd5672a.aspx