datatemplate

How to bind from a ContentTemplate to the surrounding custom Control?

I've got the following user control: <TabItem x:Name="Self" x:Class="App.MyTabItem" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:app="clr-namespace:App" > <TabItem.Header> <!-- This works --> <TextBlock Text="{B...

How do I build a DataTemplate in c# code?

I am trying to build a dropdown list for a winform interop, and I am building the dropdown in code. However, I am having a problem getting the data to bind based on the DataTemplate I specify. What am I missing? drpCreditCardNumberWpf = new ComboBox(); DataTemplate cardLayout = new DataTemplate {DataType = typeof (CreditCa...

WPF ListBox bind to index of the item

It's easy to bind something to the SelectedIndex of the ListBox, but I want every item in the ListBox be able to bind to it's index in the list. Might sound weird, so here's what I'm trying to do: <DataTemplate x:Key="ScenarioItemTemplate"> <Border Margin="8,2,8,2" Background="#FF3C3B3B" BorderBr...

Is there a workaround for the missing FindName method in Silverlight's DataTemplate?

According to the C# compiler and the Silverlight 2 documentation, Silverlight doesn't provide a FindName method for the DataTemplate class. I want to find a Border that's inside a ContentPresenter. What's the best way in SilverLight 2? ...

Switch data templates at runtime – refresh problem

Howdy, I use MVVM architecture to decouple my application. That is, you often see something like var u = new UserControl(); u.Content = new MyCustomType(); // MyCustomType is not a control The UI is defined via data templates that reside in resource dictionaries in their own XAML files <ResourceDictionary ...> <DataTemplate Data...

App crashes on changing tabs that contain ListBoxes with ItemTemplates

I have a WPF TabControl with two TabItems. Each TabItem contains a ListBox with a separate ObservableCollection as its ItemsSource. Each ListBox has a different ItemTemplate. No matter which TabItem I set to be selected at startup, that tab will be displayed fine, but when I click on the other tab the application crashes with an 'Ex...

ComboBox template problems in WPF

I have a listview with a DataTemplate that has a ComboBox. I want the ComboBox to look flat like a label until the user actually wants to change the value. I had the example below working before, but I changed things around a bit, and now it doesn't work anymore and I'm not sure why. The IsMouseOver property does not seem to be working...

How do I get the instance of a templated item from a databound ItemsControl? (WPF)

I have an <ItemsControl> with a custom <DataTemplate> (and also a custom <ItemsPanelTemplate> that is just a WrapPanel), bound via ItemsSource to a simple observable collection of strings. The DataTemplate consists simply of an instance of a custom UserControl whose properties are bound to the string via {Binding}. The problem is since...

How could I implement this strange WPF TreeListDataGridView?

As you can see in the image below I have a tree datamodel consisting of groups that can contain other groups plus an arbitary number of items wich again can hold Parameters. The Parameters itself are defined globally and just reoccur in the items. Only the parameter's actual value may differ from parameter usage to parameter usage in the...

Why is my typed data template not being applied?

I'm using Linq To Sql to fill up a listbox with Segment objects, where Segment is designer created/ORM generated class. <Window x:Class="ICTemplates.Window1" ... xmlns:local="clr-namespace:ICTemplates" Title="Window1" Height="300" Width="300"> <Window.Resources> <DataTemplate x:Key="MyTemplate"> <!-- <DataT...

WPF Datatemplating an ItemsControl

I have an ItemsControl whose ItemsSource gets bound to an ObservableCollection<Component> at run time. I have defined a data template for type Component which works fine. Now Component has a ObservableCollection<Control> and I want to add another ItemsControl inside my Component Datatemplate to render all the controls. Control here is ...

WPF Debugging datatriggers?

I am trying to do something very simple. I have a ToggleButton.IsChecked property bound to a bool. I want the background to toggle between red(false) and green(true). But for some reason it seems to be toggling between red and no background. I used a converter to check if I am getting proper notifications from the source and I am, so not...

Why is using an abstract class for DataBinding in WPF different from using an Interface?

As we all know, we can't use DataTemplates with Interfaces, but apparently (old question) we can use abstract classes. Why? The multiple inheritance argument goes for abstract classes as well... ...

What key to use if adding a data template to the resources of a control

Howdy, I have a data template that is defined in a XAML file. The root of the XAML is not a resource dictionary but the data template itself. Now I want to add this data template to the resources of a control. Unfortunately, I don't know what key to use. myControl.Resources.Add(???, dataTemplate); Although I use the data templates Da...

Blurred/Pixellated display of DataTemplate for ComboBox in WPF

I have a DataTemplate giving items for display in both a ListBox and a ComboBox. The window I have created looks like this: The question I have is why the DataTemplate in the ComboBox is blurrier or slightly more pixellated than the display in the ListBox. It is quite difficult to see on the screenshot, but it seems more noticeable whe...

Datagrid: Auto-generated DataTemplate.. StackPanel does not reflect background color

I used data binding to bind a CLR object to a datagrid (using expression blend). I was prompted to autogenerate a template to hold the data. This created a StackPanel and three TextBlocks. I go to edit the stack panel and attempt to change the various colors. The properties window accepts the change, but the panel in the data grid r...

<ColumnDefinition Width="*" /> not respected in DataTemplate

I have a WPF ListBox with a defined DataTemplate. In that template, I have a grid, where the first column width should take up all remaining room in the grid. This seems to work outside the ListBox, but not inside. Why is that, and how can I get it to behave the same? Here is my code. See line 36, and line 70 <UserControl x:Class="Ru...

dynamic datatemplates silverlight events.

Hello all, Looking for information on how to hook events to DataTemplate for silverlight using code only. This will crash my browser when rendered. private DataTemplate Create(Type type) { DataTemplate dt = new DataTemplate(); string xaml = "<DataTemplate x:Name='dt' xmlns='http://schemas.microsoft.c...

Concatenate strings instead of using a stack of TextBlocks

I want to show a list of Customer objects in a WPF ItemsControl. I've created a DataTemplate for this: <DataTemplate DataType="{x:Type myNameSpace:Customer}"> <StackPanel Orientation="Horizontal" Margin="10"> <CheckBox"></CheckBox> <TextBlock Text="{Binding Path=Number}"></TextBlock> <Text...

How do I display a single item using a DataTemplate in Silverlight?

I am trying to display a single item (not contained in a collection) using a DataTemplate. Here's what I've got so far, which is displaying nothing. Replacing ItemsControl with ListBox displays an empty listbox (so I know the element is there). <ItemsControl ItemsSource="{Binding Session}" ItemTemplate="{...