为 telerik:GridViewDataControl WPF 控件的整行绑定背景(颜色)
我有以下类:
public class ErrorMessage
{
public enum Severity { Error, Warning}
public ErrorMessage(Severity severity, string description)
{
this.severity = severity;
this.description = description;
}
public Severity severity { get; set; }
public string description { get; set; }
public string background
{
get
{
switch (this.severity)
{
case Severity.Error: return "Red";
case Severity.Warning: return "Yellow";
default: throw new Exception("severity out of bounds");
}
}
}
}
并且我将 ErrorMessage 列表绑定到 telerik GridViewDataControl WPF 控件:
<telerik:GridViewDataControl Margin="0" telerik:StyleManager.Theme="Office_Silver" Name="errorsGridView" AutoGenerateColumns="False" CanUserSortColumns="False" IsFilteringAllowed="False" ShowGroupPanel="False">
<telerik:GridViewDataControl.Columns>
<telerik:GridViewDataColumn IsReadOnly="True" UniqueName="{x:Null}" Header="Severity" DataMemberBinding="{Binding severity}" />
<telerik:GridViewDataColumn IsReadOnly="True" UniqueName="{x:Null}" Header="Description" DataMemberBinding="{Binding description}" />
</telerik:GridViewDataControl.Columns>
</telerik:GridViewDataControl>
我希望每行的整个背景颜色由 ErrorMessage.background 属性绑定。我该怎么做?提前致谢!
I have the following class:
public class ErrorMessage
{
public enum Severity { Error, Warning}
public ErrorMessage(Severity severity, string description)
{
this.severity = severity;
this.description = description;
}
public Severity severity { get; set; }
public string description { get; set; }
public string background
{
get
{
switch (this.severity)
{
case Severity.Error: return "Red";
case Severity.Warning: return "Yellow";
default: throw new Exception("severity out of bounds");
}
}
}
}
And I am binding a List of ErrorMessage to a telerik GridViewDataControl WPF control:
<telerik:GridViewDataControl Margin="0" telerik:StyleManager.Theme="Office_Silver" Name="errorsGridView" AutoGenerateColumns="False" CanUserSortColumns="False" IsFilteringAllowed="False" ShowGroupPanel="False">
<telerik:GridViewDataControl.Columns>
<telerik:GridViewDataColumn IsReadOnly="True" UniqueName="{x:Null}" Header="Severity" DataMemberBinding="{Binding severity}" />
<telerik:GridViewDataColumn IsReadOnly="True" UniqueName="{x:Null}" Header="Description" DataMemberBinding="{Binding description}" />
</telerik:GridViewDataControl.Columns>
</telerik:GridViewDataControl>
I would like the entire Background color of each row to be bound to by the ErrorMessage.background property. How do I do this? Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
另一种方法是使用具有类绑定的 RowStyle。为了避免使用任何转换器甚至事件,请将您的 ErrorMessage 代码更改为如下所示:
然后添加此资源:
在 RadGridView 上:
稍微不同的方法,但刚刚测试过它,它肯定有效。 :)
Another method is to use a RowStyle that has binding from your class. To avoid having to use any converter or even an event, change your ErrorMessage code to something like this:
And then add this resource:
And on RadGridView:
Slightly different approach, but just tested it and it definitely works. :)