Click here to Skip to main content
15,891,529 members
Everything / DataTemplate

DataTemplate

DataTemplate

Great Reads

by Gil Yoder
In this article, I describe how to display data from a simple XML file in a WPF TreeView control.
by Gerald Gomes
This article will make an attempt to describe a basic way to start implementing animation in WPF.
by Pete O'Hanlon
Switching data templates entirely in XAML.
by Shweta Lodha
How to format strings in binding

Latest Articles

by Vitalii Novotarskyi
To simplify working with jQuery Datatables.
by Mr.PoorEnglish
Understanding Tabcontrol right enables a lightweigth solution
by Gerald Gomes
This article will make an attempt to describe a basic way to start implementing animation in WPF.
by Shweta Lodha
How to format strings in binding

All Articles

Sort by Updated

DataTemplate 

27 Jan 2014 by Abhinav S
Try http://techiethings.blogspot.in/2010/05/get-wpf-datagrid-row-and-cell.html[^]http://www.valuedinformation.info/2013/06/how-to-get-datagrid-selected-row-column.html[^]
7 Aug 2013 by Abhishek Durvasula
I have a DataTemplate in which I have a Grid layout with 2 RowDefinitions. I have a TextBox in the first row and a ComboBox in the second row.I have defined the DataTemplate in my ResourceDictionary.This is the code for the DataTemplate: ...
16 Sep 2016 by Ahmad_kelany
Hi everyoneI have a DataTemplate : ...
21 Mar 2012 by Alimjan Yasin
I have a class which used as DataSourcenamespace DictMainUI.Model{ class SearchListItem:INotifyPropertyChanged { private string word; private int checkamount; ............ public string Word { get { return this.word;...
22 Mar 2012 by Alimjan Yasin
I want to define a DataTemplate of listboxitem in a ResourceDictionary. when mapping I got error. class is:namespace DictMainUI.Model{ public class SearchListItem:INotifyPropertyChanged {.............}}the Mainwindow 's namespace is DictMainUI, but namespace of my...
22 Mar 2012 by Alimjan Yasin
I don't know what happened to the project, after tried to fix it many times I give up on that project , and build whole new project and mapping custome class to resourcedictionary is worked on this one.
22 Mar 2012 by Alimjan Yasin
looks like the problem is with the project, but I do not know excatly. since I created a whole new project and tried mapping custome class to resourcedictionary and it worked. I don't why , but it worked.
30 Mar 2012 by Alimjan Yasin
I have a Datatemplate of listboxItem. in Datatemplate I place a button and I want bind command of Button to ViewModel of UserControl (listbox inside that UserControl).I tried solutions found on internet, but all did not work.is there anyone who can provide me a artcile or tips to do...
12 Apr 2012 by Alimjan Yasin
I am having problem triggering button which place inside a Datatemplate which is designed for render listboxitems.listboxitem has a data source as shownpublic class WordListItem : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; ...
12 Apr 2012 by Alimjan Yasin
I solved the problem myself, I put name to UserControl and in bining of button specified it by setting ElementName , and it worked. by yesturday when I did something similar like it, it throw error, but today it worked
16 Apr 2012 by Alimjan Yasin
I have a listbox, its items contain button, textbllock .I successfully binded the command of button to Viewmodel,and get index of listboxitem when click button inside that listboxitem. now the problem is when I click the button inside listboxitem,the listboxitem did not selected. ...
9 Dec 2016 by Alpha21oct1989
I have prepared a view in which there is a ListView Control whose ItemSource is being populated with the XML data.However along with the XML data I also required to have a check box and 2 textboxes which takes two different values.What I have tried:The view has been achieved with the...
19 Jun 2014 by Alugoju Siva Krishna
I have a ListBox in my WPF application where i am generating my ListBox items using a Datatemplate so in my Datatemplate i have some textboxes where i want taborder for Textboxes, How to achieve this i tried many ways but of no use.Below is my XAML code :-
5 Dec 2010 by Basnta Padhi
Hi All, I want brief knowledge about Data Template for Customizing a control(Combo Box,List Box etc.)in WPF using C#.NET. So if anybody have any links or sample applications then share it with me please..Update: I got to know the DataTemplate in some what but now I want to know...
29 May 2015 by Bernhard Hiller
There is some strange behavior of a binding getting lost. I experienced something similar with a combination of a combobox and a textbox, with Textbox.Text bound to the ID property of a DependencyProperty which is in turn bound to the SelectedItem of the combobox; the user could type the id...
3 Nov 2015 by Carlos Calzadilla
What is my style missing that I am unable to support DisplayMemberPath correctly? My object is showing as just the namespace and not the display value that it binds to. When I comment out my entire style for combobox & comboboxitem the binding works as intended but I lost the visual the app...
11 Jun 2014 by Carlos Liu
I do not know how to upload images and attachment here, so please go to below location http://stackoverflow.com/q/24158059/136126?sem=2
23 May 2022 by Chris Copeland
Why do you have 60 different MachineX properties instead of just having an ObservableCollection? Having individual fields is going to not only make your code incredibly difficult to maintain, but you're also going to make an incredible...
9 Feb 2016 by Daniel unknown Person
Hello,I wanted to create a friendlist for my WPF MVVM (Light Toolkit) Application, which will get filled from database generated User Objects (in ObservableCollection, List?) and should be displayed as following: ClickI'm using MahApps Metro and would use Tiles in a WrapPanel for each...
25 May 2012 by db7uk
you could, in your viewmodel bind the SelectedValue of the listbox to a property.When you select the button you would file a delegate command with a payload of the listbox item. This item can then be placed into the viewmodel property for the bound selectedvalue.
18 Jun 2011 by devi42
I'm trying to set up a TreeView in code only from a "flat" list of data objects. I looked at Bea Stollnitz' example, which uses XAML, but I have not been successful in translating it to code-only. I have:ObservableCollection myAnimals = new ObservableCollection();myAnimals.Add(new...
7 Feb 2011 by Espen Harlinn
Try setting HorizontalAlignment[^] to Stretch[^] for the UserControl ... ( and possibly check that the width is not set in xaml for the UserControl )RegardsEspen Harlinn
6 Jul 2010 by Estys
Let me correct you :At the moment you see a solution where more than 1500 columns are necessary.You don't WANT to use them. Can you not see the problem of management?What problem could need 1500+ columns?Do you maybe mean Rows?Cheers
24 Mar 2014 by FarhanShariff
I want to Display results of the list .Is it possible to display the list in console (program is windows form)as list excludedNames has many values. Which is the best way to display the result.?.private void bt_compare_Click(object sender, EventArgs e) { ...
23 Aug 2021 by Flidrip
I am trying to export my DataGrid (name: myDataGrid) to .csv - but have ran into some issues. export as intended, but my and do not. Their cells end up empty. Here's the XAML for...
5 May 2014 by Gerald Gomes
This article will make an attempt to describe a basic way to start implementing animation in WPF.
6 Mar 2019 by Gerry Schmitz
Create a class for your "string" and "width". Load a collection (List or ObserveableCollection) with instances of that class. Set the ItemSource to this collection. Bind the TextBlock "Text" and "Width" to the corresponding properties of the new "string and width" class. (What you're...
23 Jan 2012 by Gil Yoder
In this article, I describe how to display data from a simple XML file in a WPF TreeView control.
12 Aug 2018 by Graeme_Grant
I did a quick Google Search: how to disable wpf datagrid row - Google Search[^] And found this: Unable to disable rows in WPF DataGrid using Style trigger - Stack Overflow[^]
6 Mar 2019 by hamid18
Hi, I am trying to learn WPF. The DataContext is set to ViewModel. In Itemscontrol I am getting a list named"MyList". By default the datacontext of datatemplate would be string. So I modified the datacontext of TextBlock to Viemodel to access the property MyWidth which is binded to...
12 Jul 2010 by HaNnOuU
Hi everybody.I am doing a project with WPF, it's the first time, so i am not an expert in WPF, and i have some problems with treeView.I am trying to create a treeView from an instance of my class menu. A menu is composed by Items and every Item can have a collection of subItems, which can...
6 Aug 2014 by jadavparesh06
You Can Add One More Property in your DataSource for DisLike/Like and using Binding You can set this property to your buttons. This way you will be able to User dislike/Like buttons for each and every comic value that you have. Hope this Will Work. Happy Coding.
27 Jun 2013 by Jason Gleim
I'm going to expand my comment...ItemSource is meant to be bound to an object that supports property change notification. What you should do is implement INotifyPropertyChanged on your class (I'm assuming the code-behind for that page) then add a property for each ItemSource:public...
2 Dec 2011 by Jignesh J patel
i have table in logical name and i want to display it in other name how can i do that?
21 Aug 2011 by Jorge J. Martins
I have a combobox with an ItemTemplate: In both events ("_SELECCIONADO_Checked" and...
21 Aug 2011 by Jorge J. Martins
Here's how I did it: public object GetParentByType(string TypeOfParent, object ChildObject) { string LocalTypeOfParent = "System.Windows.Controls." + TypeOfParent; DependencyObject SearchChildObject = ChildObject as DependencyObject; ...
16 Jun 2011 by JV9999
Woops my bad, I thought your code was ASP.NET...Have a look here for WPF specific ways:Ways to find controls in WPF[^]Finding controls in WPF[^]Don't know of a way to do this in XAML, you might be able to do it with binding.
21 Jul 2012 by Kenneth Haugland
Sorry, I thionk I got in now:http://stackoverflow.com/questions/1786031/applying-a-fontfamily-to-all-controls-in-silverlight-4-beta[^]And this code would make them equal: ...
14 Aug 2012 by Kenneth Haugland
THere is a couple of way to do this, the simplest is to make the overall datatemplete size adusteble, and binde the child values to this parent. If that wont solve your problem then I need more information to help you :)
1 May 2013 by Kenneth Haugland
I usuall put the DataTemplate in a GridView control:http://huydinhpham.blogspot.no/2008/11/using-listvew-to-display-complex-data.html[^]or you could do it with the ItemsTemplate like this:http://stackoverflow.com/questions/483542/listbox-with-itemtemplate-and-scrollbar[^]
27 Jan 2014 by kingsa
Hi , I want to show records below manner in wpf application can u guide me or send snippets using c#.net, with paging Ahmaed Sno Place Age gender 01 Hyderabad 25 Male Rajesj Sno name Age...
26 Jan 2014 by kingsa
Hi, i have a datagrid hyper link column when ever click i need to retrive whole row data can u guide or send snippets ...
1 Jun 2013 by koleraba
Try defining your ValidationTemplate as follows:
27 Jun 2013 by kpolecastro
Imagine the items in triplicate for the different listboxes Source="{Binding Source={x:Static Application.Current}, Path=CurrentList}" x:Key="CurrentList" /> > ...
27 Jun 2013 by kpolecastro
To anyone that can help or show me a better way. I have tried to do this with an observable collection, a list based on a custom class, global/non-global collections, using the listbox's itemssource, synclocking, and finally emptying and manually entering in items.It tends to work fine, but...
7 Feb 2011 by Lordrol
Hi,I have a problem with a user control in a DataGrid.I have add the usercontrol to the DataGridTemplateColumn, like this ...
8 Feb 2011 by Lordrol
thanks, the problem was not the usercontrol, but an other element on the control.for the next time i know it
6 May 2013 by m.bleimuth
Hi Experts,I have a Problem accessing a Listbox which is defined in a datatemplate. Here is my XAML:
8 Mar 2011 by m@dhu
foreach (DataListItem dli in DataList1.Items) { Label Label1 = dli.FindControl("Label1") as Label; string lblValue=Label1.Text;}//In Datalist events.Label Label1 = e.Item.FindControl("Label1") as Label;//can get the value in string...
11 Mar 2010 by Marcelo Ricardo de Oliveira
HiI have a problem when using a TextBox with TextWrapping=Wrap which is inside a DataTemplate which is inside a ListBox which is inside a StackPanel.The problem is: when I add new lines to the TextBox, both the ListBox and the StackPanel expand accordingly, but when I remove lines from...
18 Jun 2011 by Mark Salsbery
Something like this maybe... StringReader stringReader = new StringReader("
21 Feb 2014 by Member 10609511
Hi everyone,Basically I want to display data from two tables in my database within Visual studio 2010 into one data gridview. Just a brief background to my project - it is a website where users can upload content(Images and video). I have three tables - one table 'Incident' stores the...
12 Aug 2018 by Member 12658724
WPf Datagrid. I have a button in the view; when I click it. It insert the new blank row in the grid. public ObservableCollection GridCollection { get; set; } public void AddNewRow() { GridCollection.Insert(0, new MyaModel()); } My requirement is that I want all the cells in the...
7 Apr 2018 by Member 13720457
Hello, I am developing a UWP application for Windows 10. I have embedded a textbox into a Listview, but I can't get the value of this textbox (probably due to the fact that the textbox is in a DataTemplate). Thanks for helping me, this is my first UWA app (I was developing before in...
21 Jul 2012 by mohammadghaderian.bp
HiPlease look at this sample.I have a silverlight project. it has a style file that merged with app.xamlMy global style : ...
26 May 2015 by Mohanv23
Please help to fix the below issue. I have Combobox inside listbox item datatemplate so that I can load multiple combobox but same itemsource
12 Dec 2014 by Mr.PoorEnglish
Understanding Tabcontrol right enables a lightweigth solution
13 Jun 2012 by NeonMika
Hey XML gurus out there.I have a little problem designing my Window.I have a ListBox and it's items should get the following template:[Picture][Name][Description][LikeCount]The Picture is 56 pixels width, the name 120 and the LikeCount 60 pixels. The Description should be auto-resizing...
26 Feb 2014 by NeonMika
Hello guys!It's a pretty long time since my last WPF code, so this is probably an easy question I just don't know the answer to.I have a TreeView that contains different types: Milestone, Issue, ProjectTask, etc.Now dependent on the selected item I want to get an info panel filled.I...
4 Jun 2014 by NeonMika
So, I found a solution for my question here: http://stackoverflow.com/questions/1152128/wpf-databind-to-a-stackpanel-using-datatemplates[^]Replacing the StackPanel with a ContentPresenter and instead of DataContext using the Content property worked for me.Probably it will help someone...
4 Jun 2014 by NeonMika
Hi there!Today I have another question I cannot find a solution for.I have the following data templates in the Ressources-Section of my window:
5 Jun 2014 by NeonMika
Finally, I found it out myself:The datatype has be be writtenDataType="{x:Type crosswordFields:EmptyField}">and notDataType="x:Type crosswordFields:EmptyField">The missing brackets don't get highlighted, but causing it not to run correct.But at least I found it out :P
13 Jun 2012 by Nestor Arturo
Hi... the key is to restrict the horizontal scrolling:
8 Mar 2011 by Niranjankr
You can try :string id=((lable)Datalis1.findcontrol["lable1"]).Text;
22 Jun 2014 by nirav raval
Can you please try :Change TabIndex="0"...You are nesting your controls, so, no need to maintain sequence. (not tested), hope it will solve your problem.Also you are using LostFocus event for some process, check if it does redirect your focus to somewhere else...
23 Dec 2012 by Oleksandr Kulchytskyi
Hi, DataTemplate code is not enough!Provide community with your MVVM model, and so on...Fisrt thing that comes to my mind is:- your model must to inherit IDataErrorInfo interface.
7 Aug 2014 by OneOne Six
I'm trying to make a funny comic/meme app like funnyjunk.com, which contains a dislike and a like buttons on every comic, like this : http://s9.postimg.org/ikiyo7iy7/funnyjunk.pngMy problem is: I can't get access to code the dislike/like buttons inside the DataTemplate from code behind. Is...
24 Mar 2014 by OriginalGriff
In a console, you don't get a lot of options: Console.WriteLine is pretty much your lot:foreach (string s in excludedNames) { Console.WriteLine(s); }
6 Jul 2010 by P.T.R.K
Hi All,I want use to more than 1500 columns in a datatable.Is possible?For Example,If I have less than 750 columns in a datatable which have updated properlyPlease update asap.Thanks in advanceRameshkumar.T
1 Mar 2018 by patrick.harkin
I have an application which manages audio recordings. In theory, new recording of "My Series" go in a folder "\\Library\My Series" but there are two complications. Firstly, new recordings may come to me with alternate names; for example "Macbeth" might become "William Shakespeare's Macbeth"....
1 Mar 2018 by patrick.harkin
I've written a Converter which accepts the current node and returns the text of the seriestitle child node. I haven't written the Convertback yet though! public class seriesTitleConverter : IValueConverter { public Object Convert(object value, Type targetType, object parameter,...
10 Sep 2012 by Peltchag
In a WPF client application, I'm having some difficulties using hierarchical data template to load databound menuitems.First I created the ViewModel, containing the basic properties for a menu item : Title, Command, ImageSource (Path to the image to use for Icon property) and sub...
29 Jul 2013 by Pete O'Hanlon
Switching data templates entirely in XAML.
21 Feb 2014 by Peter Leow
I figured that you want to display username (available in user_acc table) and business name (available in business table) along side related data from incident table in one gridview. then you got to join the 3 tables like this, assuming that you have a user_id field and business_id field in the...
1 May 2013 by Pheonyx
Hi guys,So I am working on a routine that validates and imports some data between two systems.both routines output their results into a list of objects and I am trying to bind to this list in my GUI.What I would like to achieve is that each type of result, be it a validation result...
28 May 2013 by Pheonyx
Hi,I have a query that so far I haven't been able to find a solution too.I have several datatemplates that are to be applied to a ListBox as follows: ...
27 Jun 2013 by Pheonyx
I've seen similar issues, and managed to fix them by re-working the code.The first change I would make would be with these:Try For I = Me.ParentListbox.Items.Count - 1 To 0 Step -1 Me.ParentListbox.Items.RemoveAt(I) NextCatchEnd TryTry For I =...
27 Jan 2014 by praveen_07
private void btn_Click(object sender, RoutedEventArgs e) { if (dtgrd.SelectedItems.Count > 0) { for (int i = 0; i
2 Dec 2010 by Pritesh Aryan
This link May Help you..........http://www.wpftutorial.net/[^]Thanks.........
8 Aug 2013 by Punamchand Dhuppad
Hey Abhishek, Just look at here what I did,1) First of all I took one ListBox in Xaml and assign its ItemTemplate property like this - 2)In code behind I wrote code something like this- List Items...
6 Aug 2014 by Punamchand Dhuppad
Yes your understanding is correct. We can not access DataTemplate controls in code behind. So for this you have to use ICommand interface inside your ViewModel. So it is clear that you should be use MVVM pattern. And important is that use of Command property is not a complex task.Can you...
14 Apr 2014 by PythonesqueSpam
Trying to get the following working with a Panorama on Windows Phone 8:TemplateSelector classpublic abstract class TemplateSelector : ContentControl{ public abstract DataTemplate SelectTemplate(object item, DependencyObject container); protected override void...
19 Jul 2015 by Reatellino
Hi guys. I'm just trying to create my custom ListView. Beacouse I want make it look nice I'm using DataTemplate. The thing is that I want to have hardcoded dummy data just for design time(no data binding at the moment).For some reason it's not working despite the fact is very simple:)Please...
21 Feb 2014 by Sandip.Nascar
You have several options here - 1. If you have links between the tables, use a query with join and make a one datatable to view it in one grid view2. If there are no relations at all between tables, I don't see any reason to use one grid view to show all the 3 tables. Create a link at the...
8 Mar 2011 by se.nishant
i want data from a label of data list in asp.neti created a template of data list and use a labelafter binding data in label i want to access the value of label
12 Sep 2013 by Shahare
Hi allI'm trying to get a DatatTemplate from a ResourceDictionary in code. The problem is when I'm trying to save it to string I get all the Binding location to be either empty or null.Here is my piece of code ResourceDictionary dictionary = new ResourceDictionary(); ...
12 Sep 2013 by Shahare
It turns out I need to register a binding converter for BindingExpression in TypeConverter in order for the serialize to work on bindings as by default they are not serialized.Needs to add this class as the ExpressionConverter public class BindingConverter : ExpressionConverter ...
21 Mar 2012 by Shmuel Zang
If the namespace is in another assembly, you have to provide the assembly's name too, like the following:
14 Dec 2013 by Shweta Lodha
How to format strings in binding
20 Aug 2011 by Simon Bang Terkildsen
I would suggest you read Understanding the Visual Tree and Logical Tree in WPF[^] to understand the difference between the logical and visual tree.But in the case you describe here that is not needed, you can just do CriteriosOpcoesComboChecks.ItemsSource
22 Aug 2011 by Simon Bang Terkildsen
When you use a ControlTemplate you're going to change the look of the control, you can use Blend to get the original so you can have the exact same. But in you case using a ControlTemplate is overkill just use a Setter to set the background color to the color for when Text is not "18" and then...
22 Aug 2011 by somasekhar_37
I'm new to WPF....I have tried implementing controltemplate and datatriggers both for textbox..I want to change the background color of the textbox when the value entered in that is not "18" through datatriggers..(i want the controlproperty for the textbox to work as it is)how can i achieve...
26 Jun 2011 by stukselbax
I've got problem to define items in my ItemsControls (or in my view or viewModel). May be I don't know something about mvvm, but here is the question. I have DataTemplate defined as
11 May 2011 by Super Lloyd
A much simpler composite application library.
17 Mar 2010 by Suthagar.p
It seems to be, once the window is rendered with the container then we need to again render it.The work around for this would be setting the scroll bar to the textbox
18 Jan 2016 by Sébastien Bancquart
Hi !I'm using a DataTemplateSelector to allow users to edit several items in my software. All these items can be of several types.My DataTemplates mainly consist of a viewer (TextBox, Image,...) and some buttons dealing actions on the DataContext. I access to it using code like this :...
21 Oct 2018 by TheBigBearNow
Hello all, I have been working on figuring out this problem for quite some time now. I am pulling a user object from a database and displaying it in a listview in WPF C#. I can read the data and I have the data separated in columns. I have a Boolean value(bit) in SQL and in my column it displays...
18 Sep 2011 by theHollow
HelloYou should make a Command, like you mentioned.You can access the Command in many ways, like this for one example:
10 Sep 2012 by Thomas Duwe
Hi Peltchag,I had the same problem and AFAIK this isn't possible for resource dictionaries.What I ended up with is using a ValueConverter in my DataTemplate.Make the converter accessible (where local is an alias for the namespace)