Styling Ribbon from the RibbonControlsLibrary

别来无恙 提交于 2019-12-06 15:09:25

问题


Ribbon is nice. I want to make it nicer... (IMHO)

With the Ribbon (from RibbonControlsLibrary on .NET 3.5 sp1), it is ok to change some backgrounds and foregrounds. But the thing I want to re-style is the white "mask" (linear gradient brush with alpha) that seats in the "background" of the RibbonTabGroup. I saw it with Snoop. I found it in the style.

<LinearGradientBrush x:Key="[49] Í" StartPoint="0.5,0.0" EndPoint="0.5,1.0">
    <GradientStop Color="#EEFFFFFF" Offset="0.0" />
    <GradientStop Color="#BBFFFFFF" Offset="0.1" />
    <GradientStop Color="#05FFFFFF" Offset="0.5" />
    <GradientStop Color="#20FFFFFF" Offset="1.0" />
</LinearGradientBrush>

But still I have no idea how to override it. I don't know either where it is set... Cheers, Patrick


回答1:


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



来源:https://stackoverflow.com/questions/5154094/styling-ribbon-from-the-ribboncontrolslibrary

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