RowStyleSelector未调用 [英] RowStyleSelector Not Called

查看:414
本文介绍了RowStyleSelector未调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在我的资源中,我有

 < loc:DetailsRowStyleSelector x:Key =detailsRowStyleSelectorAddRowStyle ={StaticResource newItemRowStyle}StandardRowStyle ={StaticResource RowStyle}/> 

然后我的datagrid使用这样:

 < DataGrid ... 
EnableRowVirtualization =false
VirtualizingStackPanel.VirtualizationMode =Standard
RowStyleSelector ={StaticResource detailsRowStyleSelector}

调用选择器的构造函数,但是SelectStyle方法不是,我的行都看起来一样。似乎有很少的文档,但这是我的选择器的样子:

  public class DetailsRowStyleSelector:StyleSelector {
public Style AddRowStyle {get;组; }
public Style StandardRowStyle {get;组; }

public DetailsRowStyleSelector(){
Console.WriteLine(); //这被称为
}

public override Style SelectStyle(object item,DependencyObject container){
//这不叫


解决方案

最有可能的原因是您有 RowStyle ItemContainerStyle 设置在 DataGrid 中,本地或通过继承的样式。



RowStyleSelector 覆盖 ItemContainerStyleSelector ,其中包括文档中的以下声明:


请注意,如果 ItemContainerStyle属性已设置。



I'm having difficulty getting a RowStyleSelector to work with a WPF DataGrid.

In my resources, I have

<loc:DetailsRowStyleSelector x:Key="detailsRowStyleSelector" AddRowStyle="{StaticResource newItemRowStyle}" StandardRowStyle="{StaticResource RowStyle}"/>

Then my datagrid uses this like so:

<DataGrid ...
    EnableRowVirtualization="false"      
    VirtualizingStackPanel.VirtualizationMode="Standard"
    RowStyleSelector="{StaticResource detailsRowStyleSelector}"

The constructor for the selector is called, but the SelectStyle method is not, and my rows all look the same. There seems to be very little documentation on this, but this is what my selector looks like:

public class DetailsRowStyleSelector : StyleSelector {
    public Style AddRowStyle { get; set; }
    public Style StandardRowStyle { get; set; }

    public DetailsRowStyleSelector() {
        Console.WriteLine(""); // this is called
    }

    public override Style SelectStyle(object item, DependencyObject container) {
        // this is not called

解决方案

The most likely cause is that you have either the RowStyle or ItemContainerStyle set on the DataGrid, either locally or through an inherited style.

The RowStyleSelector overrides the ItemContainerStyleSelector, which includes the following statement in the documentation:

Note that this property is ignored if the ItemContainerStyle property is set.

这篇关于RowStyleSelector未调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆