c# - silverlight datagrid - 绑定(bind)每一行的样式

标签 c# silverlight xaml

我有一个 silverlight (v2) 数据网格,其中一些项目是节标题,因此必须以不同的背景颜色出现。

我正在尝试使用以下 xaml 执行此操作:

        <dg:DataGrid.RowStyle>
            <Style TargetType="dg:DataGridRow">
                <Setter Property="Background" Value="{Binding Path=Background, Mode=OneTime}" />
            </Style>
        </dg:DataGrid.RowStyle>

我希望它将数据网格行 View 模型的背景属性绑定(bind)到每一行的背景属性,但我得到一个可爱的未知 xaml 解析错误:

{System.Windows.Markup.XamlParseException: AG_E_RUNTIME_MANAGED_UNKNOWN_ERROR [Line: 16 Position: 57]
   at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
   at Etana.Survey.Silverlight.UserInterface.Views.MaximumProbableLossPage.InitializeComponent()
   at Etana.Survey.Silverlight.UserInterface.Views.MaximumProbableLossPage..ctor()}

如果我尝试明确指定“红色”而不尝试绑定(bind)样式,那么它就可以工作,所以我想知道 silverlight 是否允许我绑定(bind)这样的样式,或者是否有其他技巧。

(xaml 基于 wpf 实现,效果很好)

任何输入将不胜感激

最佳答案

将绑定(bind)更改为 TemplateBinding。例如

<dg:DataGrid.RowStyle>
            <Style TargetType="dg:DataGridRow">
                <Setter Property="Background" Value="{TemplateBinding Background, Mode=OneTime}" />
            </Style>
</dg:DataGrid.RowStyle>

关于c# - silverlight datagrid - 绑定(bind)每一行的样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1176390/

相关文章:

c# - 按 customAttribute 的值排序对象的属性

c# - 调用非 void 函数而不使用其返回值。实际发生了什么?

wpf - 为什么我无法从代码中设置 SolidColorBrush 资源值?

c# - VisualStateManager WPF 不工作

c# - WPF:将具有不同类型项目的多个级别添加到 TreeView

.net - 有没有办法在 XAML 中的绑定(bind)中使用变量值和条件?

c# - 分层 JSON 数据到分层表

c# - 条件样式 : if (0 == resultIndex) vs if (resultIndex ==0)

.net - 银光 4 PLINQ

c# - 使用泛型类实现非泛型接口(interface)