Home Forums WPF controls Xceed DataGrid for WPF Help with Custom Views

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

    I looked at the sample that colors data rows blue or pink based on if the “TitleOfCoutesy” Field is “Mr.” or “Mrs.” But what if I want to color a row a certain color based on if my order ID is between 10 and 15, etc. Thanks.

    Imported from legacy forums. Posted by Brad (had 3747 views)

    User (Old forums)
    Member
    Post count: 23064

    Actually that doesn’t seem to be the major problem. I assume I could do something like that with multiple data triggers. The main problem I seem to be having is that I cannot duplicate the male/female row coloring thing in the sample. The difference in mine is that I added unbound data and specified my columns via:

    view.ItemProperties.Clear();
    view.ItemProperties.Add( new DataGridItemProperty( “FirstName”, “FirstName”, typeof( string ) ) );
    view.ItemProperties.Add( new DataGridItemProperty( “LastName”, “LastName”, typeof( string ) ) );
    view.ItemProperties.Add( new DataGridItemProperty( “Occupation”, “Occupation”, typeof( Occupation ) ) );

    Is there a reason why I’ve having trouble coloring a row by specifiying a XAML binding like the following?

    <DataTrigger Binding=”{Binding [FirstName]}” Value=”Joe”>
    <Setter Property=”Background” Value=”{StaticResource myBackground}”/>
    </DataTrigger>

    Thanks.

    Imported from legacy forums. Posted by Brad (had 272 views)

    Xceed Support
    Member
    Post count: 5658

    Let me take a look at it and I will get back to you shortly.

    Imported from legacy forums. Posted by Jenny [Xceed] (had 237 views)

    Xceed Support
    Member
    Post count: 5658

    OK, you use the brackets in the binding when you are bound to a datatable. In this case we are bound to an observable collection; therefore, omit the brackets and you should be fine. For example:

    <code>
    <Style x:Key=”dataRow_Style”
    TargetType=”{x:Type xcdg:DataRow}”>

    <Setter Property=”Background”
    Value=”LightGreen”/>

    <Style.Triggers>
    <!– To access one of the cells in the System.Data.DataRow, its name indexer must be used. –>
    <DataTrigger Binding=”{Binding Occupation}”
    Value=”Developer”>
    <Setter Property=”Background”
    Value=”LightBlue”/>
    </DataTrigger>
    </Style.Triggers>
    </Style>
    </code>

    Hope this helps!

    Imported from legacy forums. Posted by Jenny [Xceed] (had 219 views)

    User (Old forums)
    Member
    Post count: 23064

    Perfect! Works!

    Imported from legacy forums. Posted by Brad (had 191 views)

    User (Old forums)
    Member
    Post count: 23064

    Continuing with my example above with unbound data, adding columns programmatically, etc. how would I make a column that contained a rectangle that was filled with a color based on what the value of one of my properties (i.e. field in my row data structure) was? Like if fieldx were 0, it would be colored red, if fieldx were 1, it would be colored yellow, and so on. I assume it’s some sort of data template but I’m having trouble with the syntax. Thanks.

    Imported from legacy forums. Posted by Brad (had 5198 views)

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