Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7006361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:28:03+00:00 2026-05-27T21:28:03+00:00

How can I change the bound value depending on the type of the bound

  • 0

How can I change the bound value depending on the type of the bound item.

I’m using the TreeListView from Christian Ricciolo although it works just the same with the standard TreeView.

I have two classes

class Group
{
  public String Name {get;}
  public Int32 MaxItems {get;}
  public ObservableList<Item> Items {get;}
}

class Item
{
  public String Name {get;}
  public String Status {get;}
}

The XAML

<Grid>
  <r:TreeListView ItemsSource="{Binding}">
    <r:TreeListView.Resources>
      <HierarchicalDataTemplate DataType="{x:Type local:Group}" ItemsSource="{Binding Items}" />
      <DataTemplate DataType="{x:Type local:Item}" />
    </r:TreeListView.Resources>
    <r:TreeListView.Columns>
      <GridViewColumn Header="Name" DisplayMemberBinding="{Binding Path=Name}"  />
      <GridViewColumn Header="Status" DisplayMemberBinding="???" />
    </r:TreeListView.Columns>
  </r:TreeListView>
</Grid>

That works fine and I can see all groups and their items.

In the status column I want to display Item.Status and Group.Items.Count +"/"+ MaxItems depending on what is actually displayed in that row.

Currently I’m using {Binding Converter={StaticResource testConverter}} where testConverter generates the output depending on the type, but thats cumbersome and I hope there is a cleaner way.

I cannot/don’t want to create a Group.Status property.
I think I cannot use a in the data templates either, since DisplayMemberBinding overwrites them and I want to be able to do that with multiple columns/bindings.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T21:28:04+00:00Added an answer on May 27, 2026 at 9:28 pm

    The only other way I came across so far is to use the CellTemplateSelector property of the GridViewColumn. You will need to implement a DataTemplateSelector to select the proper DataTemplate. It’s a little bit cleaner in the sense that you still define the display layout/content in the xaml and just choose the appropriate template.

    Edit: Yes, you can’t use DisplayMemberBinding in this case, however DisplayMemberBinding is a simple shortcut for a TextBlock data template bound to the path. However when you use the datatemplate you can do all the binding you need in there – you don’t need the DisplayMemberBinding in this case.

    Quick example:

    <Grid>
        <Grid.Resources>
            <r:NameCellTemplateSelector x:Key="NameTemplateSelector"/>
            <r:StatusCellTemplateSelector x:Key="StatusTemplateSelector"/>
        <Grid.Resources>
    
        ...
    
        <GridViewColumn Header="Name" CellTemplateSelector={StaticResource NameTemplateSelector}  />
        <GridViewColumn Header="Status" CellTemplateSelector={StaticResource StatusTemplateSelector} />
    </Grid>
    

    And and implement the selectors:

    public class NameCellTemplateSelector : DataTemplateSelector
    {
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            FrameworkElement element = container as FrameworkElement;
    
            // find the data template with a specific x:Key
            return element.FindResource("someNameTemplate") as DataTemplate;
        }
    }
    
    public class StatusCellTemplateSelector : DataTemplateSelector
    {
        public override DataTemplate SelectTemplate(object item, DependencyObject container)
        {
            FrameworkElement element = container as FrameworkElement;
    
            // find the data template with a specific x:Key
            return element.FindResource("someStatusCellTemplate") as DataTemplate;
        }
    }
    

    You could probably also get away with just writing one selector as the container parameter is the UI element and you can walk up the visual tree to find out which column the selector is being called for and choose appropriately based on that. See also the answers to this question: Pass Data to Data Template Selector

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I understand that I can change a sql table using the follow sp: EXEC
Does anyone know how I can change the window state of a form, from
How can I re-sort my Listbox when an item's name is changed using MVVM?
I can change SQL at runtime. Can I do the same with LINQ ?
I can change the irb prompt mode with irb --prompt prompt-mode I can see
Where I can change compiler options for C# project in VisualStudio 2008 (without command
I know I can change the selectionStyle of a UITableViewCell to make it highlight
How I can change the individual region background color of viewport extjs 4. Here
I have a view where the user can change some settings, its basically a
I want a form where user can change password. I am able to encrypt

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.