datatemplate

How to expose properties of a WPF DataTemplate?

I have a data template that I use in many pages, the data template contains a few buttons, I want to hide some of these buttons by triggers (I mean setting the IsEnabled Property of these buttons in the page where I use this DataTemplate). In other words, I would even like to set in style triggers/setters a property 'ButtonXIsEnabled', ...

WPF listbox empty datatemplate

I was wondering how people handle a ListBox control that has no items? e.g. I want to bind a list of search results but if no results are found i would like to display "No results found". The way i currently tackle this is that i hide the listbox if the result set count = 0 and show a label with the "No results found" message. Ideally ...

Outside Property inside a DataTemplate WPF

Scenario: I have a ListBox and the ListBoxItems have a DataTemplate. What I want to do is put a ContextMenu in the DataTemplate. The catch is that I want this ContextMenu ItemsSource to be different depending on certain properties in the window. My initial thought is that I could just bind the ItemsSource to a Property in the window and ...

Specify a default empty DataTemplate instead of the default 'ToString()' DataTemplate

Hi, The default DataTemplate in a wpf application displays the result of the .ToString() method. I'm developing an application where the default DataTemplate should display nothing. I've tried: <Grid.Resources> <DataTemplate DataType="{x:Type System:Object}"> <Grid></Grid> </DataTemplate> </Grid.Resources> But this doesn't w...

How can I attach event handlers to items generated using databinding in WPF?

I am developing for a MS Surface unit and am using a ScatterView to display some data. The scenario below probably fits a normal ListBox (and ListBoxItems) too. When I databind the ScatterView, WPF automatically wraps the contents of the DataTemplate with ScatterViewItems. I want to attach some event handers for the ScatterManipulationC...

MVVM + Datacontext + DataTemplate + Blend = problems

Hi All, I'm currently using MVVM in a WPF project, all works very well. I have one Master view and many Detail views that I manage using a currentView property in my MasterViewModel. By using a datatemplate, I bind a view to a viewmodel. In fact, my master view has a contentcontrol whose content property is binded to my CurrentView prop...

dynamically nest DataTemplates in ListView

I have an object of Type MyTypeOneViewModel that is displayed in the first column of ListView and I have an object of Type MyTypeTwoViewModel that is displayed in the 2nd column of my ListView. Both types have a property of type MyNestedViewModel. Now I would like to display a different DataTemplate for each cell in the ListView dependin...

Focus on a Textbox in DataTemplate selected by TemplateSelector

I've got a ListView that displays different kinds of items. One of those has a textbox I want to set the focus to. I use a DataTemplateSelector to select the DataTemplate for each item. This question explains how to set the focus on a textbox in a DataTemplate. But, in this case the DataTemplate is definded directly on the ListView. In...

DataGrid: Help accessing a control defined in a CellEditingTemplate

Hello, I am using the WPF DataGrid with a DataGridTemplateColumn. The DataGridTemplateColumn.CellEditingTemplate contains a ComboBox with IsEditable set to 'true'. In my RowEditEnding event handler, I'd like to read the Text property of that ComboBox - the only problem is that I don't know how to retrieve the ComboBox instance within ...

Adding any control to any DataTemplate in .cs file

is there a way to insert an element to datatemplate in .cs file? I created datatemplate and a control e.g. a textbox. I add the datatemplate to page resource but i could not see a method to add the textbox control to the data template. My code is behind; DataTemplate dt = new DataTemplate(); TextBlock tb = new TextBlock(); tb.Text = ...

Silverlight 3: ListBox DataTemplate HorizontalAlignment

I have a ListBox with it's ItemTemplate bound to a DataTemplate. My problem is I cannot get the elements in the template to stretch to the full width of the ListBox. <ListBox x:Name="listPeople" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="0,0,0,0" Background="{x:Null}" SelectionMode="Extended" Grid.Row="1" ...

WPF - Display single entity with a data template

I Have a data template that i use in items control, i wanna know if its possible some how to use it(the template) on single item display without the items control? if not whats the best way to do it...? ...

How to apply a DataTemplate to a XElement subclass?

Hi, when I subclass from XElement, the DataTemplate that works for XElement using the element name as DatatType, doesn't work for the subclass. Any idea? <HierarchicalDataTemplate DataType="grupo" ItemsSource="{Binding Path=Elements}"> <TextBlock Text="{Binding Path=Attribute[name]}" /> </HierarchicalDataTemplate> <!-- When I bu...

WPF ListBoxItems with DataTemplates - How do I reference the CLR Object bound to ListBoxItem from within the DataTemplate?

I have a ListBox, that's bound to an ObservableCollection. Each ListBoxItem is displayed with a DataTemplate. I have a button in my DataTemplate, that when clicked, needs a reference to the member of the ObservableCollection it's part of the DataTemplate for. I can't use the ListBox.SelectedItem property because the item does not become...

Selecting DataTemplate based on sub-object type

I want to databind an ItemsCollection, but instead of rendering the collection items, I want to render sub-objects reached via a property on the collection item. To be more specific: this will be a 2D map viewer for a game (though in its current state it isn't 2D yet). I databind an ItemsControl to an ObservableCollection<Square>, where...

How do I update an existing element of an ObservableCollection?

I have an instance of ObservableCollection bound to a WPF listbox with two separate data templates (one for display, one for editing). The data template for editing has a one-way binding on the textbox, and a Save button. What changes do I need to make so that when I press the Save button (after putting the list item in edit mode), the...

WPF - DataTemplate/Value Converter for hyperlink in TextBlock

I have a ListBox showing a list of people's names, emails, departments, etc. There is a DataTemplate that has a few TextBlocks to display each property. One of these TextBlocks is wrapping a Hyperlink to show email addresses like so: <TextBlock> <Hyperlink NavigateUri="{Binding Email}"> <TextBlock Text="{Binding Email}" /> <...

Silverlight DataBinding Against CLR Objects in Blend

I love the feature in Blend where you can setup databinding to CLR Objects, and design your Silverlight control/page. My issue is around the creation of a user control that will be used as a DataTemplate. It all works great in Blend, but only at design time. The issue is that when I am editing the control in Blend, and I bind say a textb...

NullReferenceException calling RegisterName() from control in DataTemplate

I've created a custom WPF control that performs some animations on dynamically created objects. I use SetTargetName() to set animation target. (I know about SetTarget() but I need to support .NET 3.5 without SP1.) Obviously before that I need to register object names with RegisterName(). Everything works fine when my control is placed no...

WPF Memory Usage

Application: WPF Application consisting of a textbox on top and a listbox below Users type a string in the TextBox to find employees, and search results are displayed in the ListBox ListBox uses DataTemplates to display elements (shows employee name, department, phone and a thumbnail picture.) Implementation: At application startu...