Home Forums WPF controls Xceed DataGrid for WPF AutoFilter on columns of Object type

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #26344 |

    Hello all,
    please look at the following situation:

    The AutoFilter list do not display the corect DisplayMember for a specified column.

    First I have 2 classes:
    1) Adresa with 2 string properties (Oras and Judet)
    2) Person with 2 properties: one of string type, Name and the other of Adresa type, Address

    Second:
    In xaml I defined a DataGridControl, named =”grid”.
    The code in .cs is:
    public partial class Window1 : Window
    {
    List<Person> list = new List<Person>();

    public Window1()
    {
    InitializeComponent();
    Adresa ad1 = new Adresa();
    ad1.Oras = “Peretu”;
    ad1.Judet = “Teleorman”;

    Person p1 = new Person(“Liviu”);
    p1.Address = ad1;
    list.Add(p1);

    Person p2 = new Person(“Titica”);
    list.Add(p2);

    DataGridCollectionView view = new DataGridCollectionView((IEnumerable)list);
    view.AutoFilterMode = AutoFilterMode.And;
    grid.ItemsSource = view;

    Binding b = new Binding(“Address.Oras”);
    grid.Columns[“Address”].DisplayMemberBinding = b;
    }

    }

    The problem is that the AutoFilter list for Address column is not shown the correct values.
    It seems that the DataTemplate is not setted correctly. ( Into a list, I see AutoFilterExcel.Adresa text, where AutoFilterExcel is the namespace)

    For this column the data are shown correctly into the grid.
    How can I solve this problem?

    Imported from legacy forums. Posted by winnetou (had 4863 views)

    Xceed Support
    Member
    Post count: 5658

    The Column.DisplayMemberBinding is not used by default in the AutoFilterControl. The workaround for now is to redefine the AutoFilterControl’s ControlTemplate and affect the PART_DistinctValuesHost’s ItemContainerStyle.

    This must be done in a style assigned to the Column’s AutoFilterControlStyle. In this style affect the Template property with the AutoFilterControl’s ControlTemplate you defined

    This is a feature that should be in 2.1. We’ll keep you informed of the availability of the update in this thread.

    Imported from legacy forums. Posted by Chris [Xceed] (had 511 views)

    User (Old forums)
    Member
    Post count: 23064

    Hy Marcus,

    that’s work for me. One more question, please:
    For the moment I made a binding to a Oras property of Adresa object.
    Can I make a binding to DisplayBindingPath, or to a property of column ( or something else) , to be more generic?
    Because I can’t make a style for every column. I do not know at design time this.

    Thaks.

    This is my simple code:

    <DataTemplate x:Key=”listDataTemplate”>
    <DockPanel>
    <TextBlock TextTrimming=”{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type xcdg:Cell}}, Path=ParentColumn.TextTrimming}”
    TextWrapping=”{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type xcdg:Cell}}, Path=ParentColumn.TextWrapping}” >
    <TextBlock.Text>
    <Binding Path=”Oras”/>
    </TextBlock.Text>
    </TextBlock>
    </DockPanel>
    </DataTemplate>

    <Style x:Key=”ObjectOnAutoFilterControlStyle” TargetType=”{x:Type xcdg:AutoFilterControl}”>
    <Setter Property=”Template”>
    <Setter.Value>
    <ControlTemplate TargetType=”{x:Type xcdg:AutoFilterControl}”>
    <ControlTemplate.Resources>
    <Style x:Key=”objectListBoxItemStyle” TargetType=”ListBoxItem”>
    <Setter Property=”Template”>
    <Setter.Value>
    <!–Default Style for ListBoxItem–>
    <ControlTemplate TargetType=”{x:Type ListBoxItem}”>
    <Border Background=”{TemplateBinding Background}”
    BorderBrush=”{TemplateBinding BorderBrush}”
    BorderThickness=”{TemplateBinding BorderThickness}”>
    <CheckBox Content=”{TemplateBinding Content}”
    ContentTemplate=”{StaticResource listDataTemplate}”
    Foreground=”{TemplateBinding Foreground}”
    IsChecked=”{Binding RelativeSource={RelativeSource TemplatedParent},Path=IsSelected, Mode=TwoWay}”
    Margin=”2″ />
    </Border>
    </ControlTemplate>
    </Setter.Value>
    </Setter>
    </Style>
    </ControlTemplate.Resources>

    <Border x:Name=”autoFilterControlBorder”
    Background=”{TemplateBinding Background}”
    BorderBrush=”{TemplateBinding BorderBrush}”
    BorderThickness=”{TemplateBinding BorderThickness}”>
    <Grid>
    <Grid.RowDefinitions>
    <RowDefinition Height=”Auto”/>
    <RowDefinition Height=”*”/>
    </Grid.RowDefinitions>

    <!–Button used to clear the selection–>
    <Button Grid.Row=”0″
    MinHeight=”24″
    Content=”{TemplateBinding ClearAutoFilterText}”
    Command=”xcdg:AutoFilterControl.ClearAutoFilterValues”
    CommandParameter=”{TemplateBinding AutoFilterColumn}”
    Foreground=”{TemplateBinding Foreground}”/>

    <!–The ListBox used to display the DistinctValues for this column must be named
    PART_DistinctValuesHost–>
    <ListBox x:Name=”PART_DistinctValuesHost”
    Grid.Row=”1″
    Background=”{TemplateBinding Background}”
    BorderThickness=”0″
    Foreground=”{TemplateBinding Foreground}”
    ItemContainerStyle=”{StaticResource objectListBoxItemStyle}”
    SelectionMode=”Multiple”>
    </ListBox>
    </Grid>
    </Border>
    </ControlTemplate>
    </Setter.Value>
    </Setter>
    </Style>

    Imported from legacy forums. Posted by winnetou (had 595 views)

    Xceed Support
    Member
    Post count: 5658

    In your “objectListBoxItemStyle”, bind the ContentTemplate property to the AutoFiltercontrol’s AutoFilterColumn (the column associated to the AutoFilterControl) as follow:

    ContentTemplate=”{Binding RelativeSource={RelativeSource AncestorType={x:Type xcdg:AutoFilterControl}}, Path=AutoFilterColumn.CellContentTemplate}”

    Imported from legacy forums. Posted by Chris [Xceed] (had 384 views)

    User (Old forums)
    Member
    Post count: 23064

    Hi Christ,

    this not working. see the new style:
    I’m doing something wrong?

    <Style x:Key=”objectListBoxItemStyle” TargetType=”ListBoxItem”>
    <Setter Property=”Template”>
    <Setter.Value>
    <!–Default Style for ListBoxItem–>
    <ControlTemplate TargetType=”{x:Type ListBoxItem}”>
    <Border Background=”{TemplateBinding Background}”
    BorderBrush=”{TemplateBinding BorderBrush}”
    BorderThickness=”{TemplateBinding BorderThickness}”>
    <CheckBox Content=”{TemplateBinding Content}”
    ContentTemplate=”{Binding RelativeSource={RelativeSource AncestorType={x:Type xcdg:AutoFilterControl}}, Path=AutoFilterColumn.CellContentTemplate}”
    Foreground=”{TemplateBinding Foreground}”
    IsChecked=”{Binding RelativeSource={RelativeSource TemplatedParent},Path=IsSelected, Mode=TwoWay}”
    Margin=”2″ />
    </Border>
    </ControlTemplate>
    </Setter.Value>
    </Setter>
    </Style>

    Imported from legacy forums. Posted by winnetou (had 354 views)

    Xceed Support
    Member
    Post count: 5658

    Hi winnetou,

    I missed the DisplayMemberBinding point. Since you want to display the Oras property of the Address DataItem in the Column, you must set the CheckBox ContentProperty to “{Binding Path=Oras}”

    if you use “{TemplateBinding Content}”, you will bind the Address DataItem directly

    Imported from legacy forums. Posted by Chris [Xceed] (had 420 views)

    User (Old forums)
    Member
    Post count: 23064

    Christ,

    this is what i was doing initially. I bounded the Content property directly to Oras property of the Address. But I want something generic, because in this way I must to make a style for each column of object type.
    On the other hand, the columns collection is given at runtime.

    Thanks

    Imported from legacy forums. Posted by winnetou (had 428 views)

    Xceed Support
    Member
    Post count: 5658

    Hi winnetou,

    The necessity of styling the AutoFilterControl for each Column is a limitation and will be addressed in next release. By now, the only way to get the desired behavior would be to set the Column.CellContentTemplate using your “listDataTemplate” and use the binding to AutoFilterColumn.CellContentTemplate in the ListBoxItem style defined inside the Control template for the AutoFilterControl.

    We will keep you informed of the availability on this forum post.

    Imported from legacy forums. Posted by Chris [Xceed] (had 6486 views)

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.