Questions tagged [datatemplateselector]
140 questions
32
votes
5 answers
WPF: Reapply DataTemplateSelector when a certain value changes
So here is the XAML that I have:
Here is my ListTemplateSelector class:
public class…

Nick
- 2,265
- 7
- 30
- 34
31
votes
4 answers
How to trigger DataTemplateSelector when property changes?
I have ContentPresenter with DataTemplateSelector:
...
public override DataTemplate SelectTemplate(object item, DependencyObject container)
{
var model = item as ItemControlViewModel;
if (model.CurrentStatus ==…

mxpv
- 946
- 2
- 10
- 31
20
votes
4 answers
Explicitly refresh DataTemplate from a DataTemplateSelector?
I set up a ContentControl.DataTemplateSelector to my desired one.
I want that according to a command or whatever, call the ContentControl to reselect the template from the selector by either xaml or code.
Thank

Shimmy Weitzhandler
- 101,809
- 122
- 424
- 632
20
votes
2 answers
Change Data template dynamically
I have a item control which is bound to Tasks. Each task has task state. I have defined different data templates for each task state, and also data template selector.
Problem is that I am not able to figure out how to trigger data template selector…

Tilak
- 30,108
- 19
- 83
- 131
9
votes
2 answers
Why can't a DataTemplate bind to an interface when that DataTemplate was explicitly returned from a DataTemplateSelector?
I've created a DataTemplateSelector which is initialized with a collection of known interfaces. If an item passed into the selector implements one of those interfaces, the associated data template is returned.
First, here's the ICategory interface…

Mark A. Donohoe
- 28,442
- 25
- 137
- 286
9
votes
1 answer
How do I use a ItemTemplateSelector together with a HeaderTemplate in a WPF ListView?
Suppose the following XAML defined window:

Pascal
- 2,197
- 3
- 24
- 34
8
votes
1 answer
How can you enable auto-DataTemplate selection based on data type like you can with an items control?
We're writing a very specialized ItemsControl which actually has three ContentPresenter's per 'row', each bound to a different object (think poor-man's grid) instead of the more common one, like a ListBox.
Now with a ListBox if you don't explicitly…

Mark A. Donohoe
- 28,442
- 25
- 137
- 286
8
votes
3 answers
LongListSelector and DataTemplateSelector
I'm using the LongListSelector to realize List or Grid display for my items. For this, I created a DataTemplateSelector and I change the LayoutMode property at runtime. This is working but there seems to be an issue with the DataTemplateSelector. If…

zirkelc
- 1,451
- 1
- 23
- 49
7
votes
1 answer
Xamarin Use DataTemplateSelector not in ListView
I have a simple question. I have two datatemplates defined on my Xamarin Forms page. I want to swap one in for the other when a button is pressed. I know with a ListView I can use the ItemTemplate and bind to my DataTemplateSelector to change…

Jonesopolis
- 25,034
- 12
- 68
- 112
6
votes
1 answer
Can I use a DataTemplateSelector within a DataTemplate?
I have an ItemsControl using a StackPanel to display a list of items.
I would like a label to appear for each row, but for the content to the left of the label to be defined by a DataTemplateSelector. I do not want to redefine the label for each…

Greg Sansom
- 20,442
- 6
- 58
- 76
6
votes
2 answers
WPF DataGrid Binding to datatable
This is driving me nuts. I am creating a DataGrid in code and then binding it to a datatable. This is dynamic and the rows and columns will be different everytime the grid is created.
Basically I loop through my datatable and create DataGrid…

Emad
- 4,110
- 5
- 30
- 35
6
votes
2 answers
How to properly reference a class from XAML
OK, this is a super super noob question, one that I'm almost embarrassed to ask...
I want to reference a class in my XAML file. It's a DataTemplateSelector for selecting the right edit template for a DataGrid column.
Anyway, I've written the class…

Andy T
- 1,901
- 7
- 20
- 24
6
votes
3 answers
WPF DataTemplateSelector.SelectTemplate not called for a ContentControl-derived type
I'm trying to build a ContentControl-derived control (let's call it MyContentControl) that will have its ControlTemplate set by an instance of a DataTemplateSelector-derived type (let's call it MyTemplateSelector).
When I try to this:
ContentControl…

user129759
- 61
- 1
- 2
6
votes
2 answers
ContentControl with DataTemplateSelector - help needed
I got an enoying problem... Maybe someone can (please!) help.
I am using a model that has and enumeration of types and a property that should hold UI models for each selected type from enumeration: Let's define them like:
class ViewModel
{
…

Victor
- 260
- 1
- 3
- 13
5
votes
1 answer
WPF: Find Resources from UserControl within DataTemplateSelector class
I know there is this thread: How to find a resource in a UserControl from a DataTemplateSelector class in WPF?
asking the same.
BUT... I am not satisfied with the answer! THERE MUST be a way to grab the Resources of the
UserControl containing the…

Elisabeth
- 20,496
- 52
- 200
- 321