datatemplate

Underline Text in Label which is in a DataTemplate

Hello, i have a ListView which contains objects bound from an collection. The representation of the objects i have set with data-template. Now i want to do the following. There are two TextBlocks in my DataTemplate: <DataTemplate> <StackPanel> <TextBlock Text="{Binding Name}"></TextBlock> <TextBlock Text="{Binding Path...

Specifying DataTemplate.DataType with a custom type extension

I have this markup extension public class NullableExtension : TypeExtension { public NullableExtension() { } public NullableExtension( string type ) : base(type) { } public NullableExtension( Type type ) : base(type) { } public override object ProvideValue( IServiceProvider serviceProvider ...

How to Programmatically Modify a DataTemplate?

I'm trying to programmatically add events and elements to a DataTemplate in a Silverlight 3.0 app. I have a User Control with a dependency property where I would like to take the template that's set, tweak it, and then set the modified version to an inner control. The idea I have is to take the DataTemplate that comes in, read its XAML,...

Updating relative time with WPF DataTemplate

Hi! I'm using a DataTemplate to show items (from a class via data binding) in a listbox. This class also contains date and time, and I'm using a converter to convert this date/time to relative time (xx minutes ago), which is then displayed in a TextBlock. So far everything is great. The problem is that I don't know how to keep this rela...

WPF - Refresh contents of a DataTemplate

I have a tab that has its content set to an object (a TFS WorkItem). I have a DataTemplate for the WorkItem type. When I set the object to the tab it displays nicely. However, when I update one of the collections on the object (the list of links) this change is not refreshed to the view. I have tried making my WorkItem a DependencyPr...

WPF MessageBoxes and DataTemplates

I have an object that in a simplified form is as follows: public class MyObject { public bool Activate { get { MessageBox.Show("My Status"); } set { Do Some Stuff } } I have a DataTemplate that maps the "Activate" property to a check box like so: <DataTemplate x:Key="ComponentResourceKey TypeInTargetAssembly={x:Type ...

How can I create a DataTemplate for a collection?

I would like to be able to create a DataTemplate to be used when a collection is passed into a control. I am building a single control, that when passed an object, or a collection of objects, the view of the user control conforms to the template defined for the object type. for example, this is a user control I have, that switches view...

Adding DataTemplate (non-XAML) to resource dictionary in code?

I'm trying to figure out how to add a DataTemplate to the app's resource dictionary. I'm familiar with how to do so when the DataTemplate is in XAML (via a uri), but I'm kind fuzzy at how to do so when the DataTemplate is defined in code. What I have, which isn't working is- //Create DataTemplate DataTemplate template =...

WPF - Get DataTemplate without an event

I have a WPF Data template defined in my Windows.Resources section. I would like to access this (really a list box on it) via the code behind. How can I do this? I can't get what I want via an event because I want to get the reference in the completed step of a BackGroundWorker. (Ie no sender (that is a UI element) to go off of there...

WPF DataTemplate - x:Key vs DataType="{x:Type XXXX")

I have a DataTemplate that I want to find using the FrameworkElement.FindResource(). To do that I need to have a key on the data template. The problem is that x:key and assigning a data type are mutually exclusive. (Reference) So, once I set the DataType for my template, how do I find the Key value? Is there some formula that conver...

Silverlight: Events in datatemplate for listboxes

Hello, The functionality I want is to have a remove button beside each item of a listbox so when the user clicks it, that specific item gets removed from the list. I am thinking about putting it in the data template but how would I wire up an even to that? Thanks, Shawn Mclean ...

In WPF, how to databind to the Window DataContext from inside the DataTemplate of a contained ListBox?

I have a WPF Window with a view model set as its DataContext, and have a ListBox with a DataTemplate and its ItemsSource bound to the view model, like in the following example: View model: using System.Collections.Generic; namespace Example { class Member { public string Name { get; set; } public int Age { get; set; } } ...

Tab stop not working for textboxes inside data template

I'm writing a really simple name / value editor control where the value is editable - label on left and property text box on right. Control works fine except that when the user hits TAB when inside one of the "value" text boxes on the right, the focus shifts away from my control to the next control in the hiearchy. I want the focus to ...

Accessing an ItemsControl item as it is added

In a previous post, I was advised to use a DataTemplate to render a group of Buttons and Labels, and it works wonderfully. The problem is that I have several of these groups of Buttons, and I would like to distinguish one group from another. I plan to use the AlternatingIndex to color each group differently, but that's not enough -- ea...

[WPF] binding another control in DataTemplate

I'd like to show the PixelWidth & PixelHeight of the image (not thumbnail) in tooltip, But I have not idea how to do binding in the datetemplate, I try to use "{Binding ElementName=imgPreview, Path=Source.PixelWidth}"/>, but got nothing. Could anyone explain how to do it? <ListBox.ItemTemplate> <DataTemplate> ...

DataTemplate + MVVM

Hey everyone, I'm using MVVM and each View maps to a ViewModel with a convention. IE MyApp.Views.MainWindowView MyApp.ViewModels.MainWindowViewModel Is there a way to remove the DataTemplate and do it in C#? with some sort of loop? <DataTemplate DataType="{x:Type vm:MainWindowViewModel}"> <vw:MainWindowView /> </DataTemplate> ...

Is there a way to use a DataTemplate with a parameter?

I need to dynamically add/remove GridView columns, each displaying information from a different element stored in a KeyedCollection (indexed with tn 'int'). The basic technique works, but requires an index, as follows: <GridViewColumn Header="bid"> <GridViewColumn.CellTemplate> <DataTemplate> <TextBlock Width="60...

How to change ListBox DataTemplate in WPF based on CheckBox

I am trying to apply a DataTrigger to change the DataTemplate for a listbox and am getting the error "Error 1 Cannot find the Trigger target 'IssueListBox'. (The target must appear before any Setters, Triggers, or Conditions that use it.)" I have a Listbox in my Main Window (In a DockPanel along with other Controls): <ListBox x:Name...

[WPF]How to set width and height of a grid that is in a data template

Having the following wpf code: <Window x:Class="WpfApplication5.Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:c="clr-namespace:WpfApplication5" Title="Window1" Height="300" Width="300"> <Window.Resources> <c:Places x:Key="PlacesData"/> <Dat...

Inline editing TextBlock in a ListBox with Data Template (WPF)

Using WPF, I have a ListBox control with a datatemplate inside it. The relevant XAML code is shown below: <ListBox Name="_todoList" Grid.Row="1" BorderThickness="2" Drop="todoList_Drop" AllowDrop="True" HorizontalContentAlignment="Stretch" ScrollViewer.HorizontalScrollBarVisibility="Disabled" Alterna...