在运行时更改 tablix 布局方向的最佳解决方案是什么?
我想在我的报告中使用两种语言(阿拉伯语,英语)交换列顺序,我想在运行时将 Tablix 布局方向从 LTR 转换为 RTL,因为在这个道具中我无法编写表达式
新答案:我建议使用 two tablixes,除了 LayoutDirection 属性(一个是 LTR,另一个是 RTL)和 Visibility>Hidden 属性(另一个是基于参数值的表达式 - 类似于
)之外,其他选项卡都是相同的=IIf(Parameters!RTL.Value="T",True,False)
对于 LTR Tablix,反之亦然对于 RTL Tablix。
首先我将 RDLC 读取为 XML 然后在运行时更新此 XML
private static void UpdateTableLayoutDirection(string tableId, bool isRTL, XmlDocument doc)
{
var tableNode = ReportUtilities.FindFirstNodeByName(doc.DocumentElement, tableId);
if (tableNode != null)
{
string layoutAttName = "LayoutDirection";
XmlAttribute attribute = tableNode.Attributes[layoutAttName];
string rtlValue = isRTL ? "LTR" : "RTL";
if (attribute != null)
{
// Update the attribute value (replace with your logic)
attribute.Value = rtlValue;
}
else
{
// Replace "456" with the desired default value for the attribute
XmlAttribute newAttribute = doc.CreateAttribute(layoutAttName);
newAttribute.Value = rtlValue;
// Add the attribute to the node
tableNode.Attributes.Append(newAttribute);
}
}
}
tableId 是 Tablix 这个想法是找到 LayoutDirection 属性并更新它的值,然后从 XML 定义加载 RDLC 报告