【问题标题】:How to add a color to the header of a Telerik groupbox?如何为 Telerik 组框的标题添加颜色?
【发布时间】:2016-08-10 12:06:01
【问题描述】:

如何为 Telerik 分组框的标题添加颜色?

<StackPanel Orientation="Vertical">
            <telerik:GroupBox Header="Demo">
                  <StackPanel Orientation="Vertical">

【问题讨论】:

    标签: wpf xaml silverlight telerik


    【解决方案1】:

    有一些内置主题可以直接应用于 GroupBox 控件。它们提供了一些基本的样式选项,您可能会找到最适合您需要的样式。

    内置主题:http://docs.telerik.com/devtools/winforms/panels-and-labels/groupbox/themes

    但是,如果您真的不想使用内置主题而只想自定义 UI,那么您应该查看 Telerik Presentation Framework (TPF) 并设计和实现您自己的 GroupBox 控件。

    更改 GroupBox 标题颜色

    ((FillPrimitive)this.radGroupBox1.GroupBoxElement.Children[1].Children[0]).BackColor = Color.Red;
    ((FillPrimitive)this.radGroupBox1.GroupBoxElement.Children[1].Children[0]).BackColor2 = Color.Yellow;
    ((FillPrimitive)this.radGroupBox1.GroupBoxElement.Children[1].Children[0]).GradientStyle = Telerik.WinControls.Gradien
    

    有关 TPF 的更多详细信息: http://docs.telerik.com/devtools/winforms/panels-and-labels/groupbox/advanced/tpf-structure

    【讨论】:

    • FillPrimitive 用于 WinForms。我使用 WPF 或 Silverlight。
    【解决方案2】:

    正如 WoodKiddy 之前提到的,建议使用 c# 版本 - 以编程方式设置颜色。 看来 Telerik 团队自己在这里也提出了同样的建议:

    This question seems similiar to yours

    我不太习惯 xaml 结构,再次开发团队建议使用 c# 方法。但这可能会带来一些运气:

    <Style x:Key="MyGroupBoxStyle" TargetType="{x:Type GroupBox}">
     <Setter Property="HeaderTemplate">
       <Setter.Value>
         <DataTemplate>
           <TextBlock Text="{Binding}" Foreground="Black" FontWeight="Bold"/>
         </DataTemplate>
       </Setter.Value>
     </Setter>
    </Style>
    

    祝你好运!

    【讨论】:

    • 我可以在后面的代码中使用 C#。但我怀疑它只支持 WinForms。我使用 WPF 或 Silverlight。有一些内置主题可以直接应用于 GroupBox 控件。它们提供了一些基本的样式选项,您可能会找到最适合您需要的样式。内置主题适用于 WinForms。
    猜你喜欢
    • 1970-01-01
    • 2012-02-17
    • 1970-01-01
    • 1970-01-01
    • 2014-06-17
    • 1970-01-01
    • 2022-12-19
    • 2014-12-31
    • 1970-01-01
    相关资源
    最近更新 更多