动态更改样式。

Changing the style dynamically.

我想根据用户更改报告的样式/主题。
我所有的用户都有一个用户组。我的用户组有自定义样式。
所有这些信息都在数据库中。
用户样式:ID | ID 用户组 |标志 |样式 1 |颜色 1 |等..

我想用这些信息改变我的报告风格。
我知道可以给我的商品起一个样式名称。
但是我可以在后面的主报告代码中定义它吗?

奖励:我可以只对主报告执行一次吗?

基本上使用样式名称作为 CssClass。

1。程序员解决方案

If you have an aversion for the GUI, This is made for you !

第一个是 最差的,但是我想出的第一个解决方法。

可以在 StyleRules.
中定义 telerik 报告中的样式 为了根据用户管理主题,您可以使用 ReportParameter。

Telerik.Reporting.Drawing.StyleRule styleRule1 = new Telerik.Reporting.Drawing.StyleRule();
styleRule1.Selectors.AddRange(new Telerik.Reporting.Drawing.ISelector[] {
new Telerik.Reporting.Drawing.StyleSelector("MyStyle")});

if( reportParameter1.Value == "StyleUser1")
{
    styleRule1.Style.Padding.Left = Telerik.Reporting.Drawing.Unit.Point(2D);
    styleRule1.Style.Padding.Right = Telerik.Reporting.Drawing.Unit.Point(2D);
    styleRule1.Style.BackgroundColor = System.Drawing.Color.Blue;
    styleRule1.Style.Color = System.Drawing.Color.White;
    styleRule1.Style.Font.Bold = true;
    styleRule1.Style.Font.Name = "Segoe UI";
}
else {
    //default style
}

您可以将样式名称添加到设计器或构造器中的元素。
这样:

this.textBox2.StyleName = "MyStyle";

您可以在设计器中创建您的样式规则,并仅将样式分配给初始化组件中的组件。

if( reportParameter1.Value == "StyleUser1")
{
    this.textBox1.StyleName = "MyStyle";
    this.textBox2.StyleName = "MyStyle";
    this.textBox3.StyleName = "MyStyle";
}
else {
    //default style
}

2。设计器 GUI

  1. 设计你所有的style rules
  2. 使用导出它们。 Exporting and Reusing Style Sheets

您可以在后面的代码中绑定它们,过滤参数。
或者只是将它们添加到您的通话应用中。