Styling Ribbon from the RibbonControlsLibrary

时光毁灭记忆、已成空白 提交于 2019-12-04 20:40:27
Patrick

I got it!

With help of the following post Serialize a UserControl to xaml, but not its children? [Many thanks to you Will]. I could extract the "default" style. So I obtain the complete style. What I did before, open RibbonControlsLibrary with .NET Reflector and read the XAML with BAML Viewer. Not ideal in my case.

Just in case someone has the same wish, obtaining the default style of component (when it isn't published @MSDN):

  System.Windows.Style style = Application.Current.FindResource(typeof(Microsoft.Windows.Controls.Ribbon.Ribbon)) as System.Windows.Style;

  var sb = new System.Text.StringBuilder();
  var writer = System.Xml.XmlWriter.Create(sb, new System.Xml.XmlWriterSettings
  {
    Indent = true,
    ConformanceLevel = System.Xml.ConformanceLevel.Fragment,
    OmitXmlDeclaration = true
  });
  var mgr = new System.Windows.Markup.XamlDesignerSerializationManager(writer);
  mgr.XamlWriterMode = System.Windows.Markup.XamlWriterMode.Expression;
  System.Windows.Markup.XamlWriter.Save(style, mgr);
  string styleString = sb.ToString();

Cheers, Patrick

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!