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 7737433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:59:46+00:00 2026-06-01T07:59:46+00:00

Suppose the following XAML defined window: <Window x:Class=LayoutTests.Window1 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml xmlns:local=clr-namespace:LayoutTests Title=Window1> <Window.Resources> <XmlDataProvider

  • 0

Suppose the following XAML defined window:

<Window x:Class="LayoutTests.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:LayoutTests"
        Title="Window1">
  <Window.Resources>
    <XmlDataProvider x:Key="XmlData" IsInitialLoadEnabled="True">
      <x:XData>
        <Items xmlns="">
          <Item text="Item 1" type="A" />
          <Item text="Item 2" type="B" />
          <Item text="Item 3" type="A" />
        </Items>
      </x:XData>
    </XmlDataProvider>
    <DataTemplate x:Key="TypeATemplate">
      <TextBlock Text="{Binding XPath=./@text}" Foreground="Red"/>
    </DataTemplate>
    <DataTemplate x:Key="TypeBTemplate">
      <TextBlock Text="{Binding XPath=./@text}" Foreground="Green"/>
    </DataTemplate>
    <DataTemplate x:Key="HeaderTemplate">
      <TextBlock Text="A Header"/>
    </DataTemplate>
    <local:TypeSelector x:Key="TypeSelector" TypeATemplate="{StaticResource TypeATemplate}" TypeBTemplate="{StaticResource TypeBTemplate}"/>
  </Window.Resources>
    <Grid>
    <ListView ItemsSource="{Binding Source={StaticResource XmlData}, XPath='/Items/Item'}" ItemTemplateSelector="{StaticResource TypeSelector}">
      <!--<ListView.View>
        <GridView>
          <GridViewColumn Width="Auto" HeaderTemplate="{StaticResource HeaderTemplate}"/>
        </GridView>
      </ListView.View>-->
    </ListView>
  </Grid>
</Window>

And a DataTemplateSelector defined in the code behind like this:

  public class TypeSelector : DataTemplateSelector
  {
    public DataTemplate TypeATemplate { get; set; }
    public DataTemplate TypeBTemplate { get; set; }
    public override DataTemplate SelectTemplate(object item, DependencyObject container)
    {
      var element = item as XmlElement;
      if (element.Attributes["type"].Value == "A")
        return TypeATemplate;
      else
        return TypeBTemplate;
    }
  }

If the code for the header template is not commented out, the DataTypeSelector is not called anymore. How do I specify a DataTemplateSelector and HeaderTemplate at the same time?

  • 1 1 Answer
  • 0 Views
  • 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-06-01T07:59:47+00:00Added an answer on June 1, 2026 at 7:59 am

    I think what you are trying to do is style a single GridViewColumn and its Header.
    So move the TemplateSelector from the ListView to the GridViewColumn definition:

    <Grid>
      <ListView ItemsSource="{Binding Source={StaticResource XmlData}, XPath='/Items/Item'}">
      <ListView.View>
        <GridView>
          <GridViewColumn Width="Auto" CellTemplateSelector="{StaticResource TypeSelector}" HeaderTemplate="{StaticResource HeaderTemplate}"/>
        </GridView>
      </ListView.View>
      </ListView>
    </Grid>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose the following object structure: class Super {} class SubA extends Super {} class
Suppose the following: I have a database set up on database.mywebsite.com , which resolves
Suppose the following class public class Message { // some code } And a
Suppose I have following code package memoryleak; public class MemoryLeak { public static int
Suppose the following constructor: class Needed { public: Needed () {} Needed (const char
Suppose the following class hierarchy with a base class and some general case class
Suppose the following model public class Product { private Integer requiredQuantity; private Integer allowedQuantity;
Suppose the following HTML div container <div id=container> <form> <div> <label class=error>Name</label> <input type=text
Suppose the following model : class Product include MongoMapper::Document key :name, String key :product_category_id,
Suppose the following HTML: <li class=fooli> <a class=foo href=javascript:foo(this);>anchor</a> </li> <li class=fooli> <a class=foo

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.