datatemplate

WPF - prevent ListBox item selection

I would like to prevent selection of ListBoxItems in my ListBox. My DataTemplate has a checkbox and this should be the only thing the user can click or select. How can I do that? Thanks! ...

With WPF, how to retrieve the controls contained by a DataTemplate?

Basically I have a DataTemplate that contains Border, StackPanel and stuff, and later I use this DataTemplate as a ContentTemplate in many ContentControl(s). These ContentControl(s) are named, but from the C# code I don't manage to find a way to get back my Border, StackPanel and stuff from them. Any ideas? ...

Dynamic DataTemplates (pref. Silverlight)

Is it possible to have a ListBox with a Data Template that changes depending on certain properties of the ItemsSource? For instance maybe you want a list with a variety of items such as images, video, custom panels, etc. Was hoping it could behave like some sort of factory. Any ideas how this would work? ...

Bind to ItemsControl's DataContext from inside an ItemTemplate

I have an ItemsControl whose for the ItemTemplate DataTemplate contains a Button. I want the Command on the button to bind to a Command on the DataContext of the ItemsControl, not the ItemTemplate. I think the solution has to do with using RelativeSource, but my attempts so far have failed: <ItemsControl ItemsSource="{Binding Games}"> ...

WPF databinding to a list of datetime objects

I have a combo box that I want to bind to a list of datetime objects, but I want to show the datetime objects in short time format. I'm pretty sure I need to use some form of data template for this, but I can't figure out how to bind to the datetime object's ToShortTime method within the data template. Can someone point me in the right ...

WPF: How can I wrap the items in a ItemsControl in another Template?

I have an ItemsControl that contains items that each has its own DataTemplate. Each ViewModel class in the ItemsSource derives from a common ancestor that has a Header property. I want to wrap each item in a Expander control, but my problem is that I don't know how to 'carry over' each 'DataTemplate' to the DataContext of the expading p...

Access items inside the DataTemplate in WPF

Hi, I was wondering if in WPF you are able to get the actual instances of the datatemplate objects. For example in the following situation: <UserControl> <UserControl.Resources> <DataTemplate x:Key="MyTemplate"> <CustomControl ></CustomControl> </DataTemplate> </UserControl.Resources> <ListBox D...

Accessing a RenderTransform in a DataTemplate in Silverlight

I've got a bunch of ContentControls with a DataTemplate like so: <DataTemplate> <Canvas> <Canvas.RenderTransform> <TransformGroup> <ScaleTransform ScaleX="1.0" ScaleY="1.0"/> </TransformGroup> </Canvas.RenderTransform> </Canvas> ...

Conditional Data Templates in WPF

How would it be possible to choose a different datatemplate accroding the a field in the data binding source? I would have 2 different DataTemplates <DataTemplate x:Key="DataTemplateLabel"> <Label Width="60" Height="25" Background="Red"> <TextBlock Text="{Binding Path=Name}"/> </Label> </DataTemplate> <DataTemplate x:Key=...

User Control Not Rendering When Used as a DataTemplate?

Hey folks, I have a usercontrol which I want to use as a DataTemplate in a Listbox. This works: <ListBox> <ListBox.ItemTemplate> <DataTemplate> <Grid x:Name="Grid" Height="100" Width="880" Background="LightGray"> <Grid.RowDefinitions> <RowDefinition Height="24"/> <RowDefinition Height="24"/> <Ro...

How can I bind the nested viewmodels to properties of a control

I used Microsoft's Chart Control of the WPF toolkit to write my own chart control. I blogged about it here. My Chart control stacks the yaxes in the chart on top of each other. As you can read in the article this all works quite well. Now I want to create a viewmodel that controls the data and axes in the chart. So far I'm able to add a...

WPF TextBox.SelectAll () doesn't work

Hi! I have used the following template in my project: <DataTemplate x:Key="textBoxDataTemplate"> <TextBox Name="textBox" ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}" Tag="{Binding}" PreviewKeyDown="cellValueTextBoxKeyDown"> <TextBox....

WPF: Scroll into view a new item in a ItemsControl

I have an ItemsControl that is databound to a ObservableCollection. I have this method in the code behind which adds a new model to the list. I would then like to scroll the new item (at the bottom of the list) into view. I think the size of the ItemsControl is not yet updated when I am querying the size, since the ActualHeight before a...

DataTemplate at design time

In one of my first attempts with WPF I went a bit too far: I have an object that needs a different DataTemplate depending on one of its properties. In other words if (object.property=="multi") then the template should be a combo, etc. Now I 've went ahead and obviously used a DataTemplateSelector to apply the required template. And in ...

How to combine my seemingly redundant XAML

I have 8 different XAML DataTemplates that are all very similar. Here are 2 of them: <DataTemplate x:Key="ConflictFieldStringCellContentTemplate"> <StackPanel> <TextBlock Text="{Binding ClientVersion.Value}" Foreground="{Binding Path=Mismatch, Converter={StaticResource mismatchBoolToBrushConverter}}" /> ...

WPF: TextBox Text is not updating.

I have a user control that i am using inside a Data Template, this user control contains a TextBox which is binded with Value property(declared as a Dependency Property) of my user control. In data template i bind this Value property with my actual property say Name(also a Dependency Property). It works properly, i assign a value to Name...

Attaching an Event Handler to a Code Generated DataTemplate

I have a question related to this one: I'm trying to attach an event to my StackPanel but it doesn't appear to connect when using the XamlReader. I can't get the ChildItem_Load method to get called. Does anyone know of a way to do this? Other than this event the code works fine. this._listBox.ItemTemplate = (DataTemplate) XamlReader.Lo...

How to have classes of DataTemplates?

In my application, I would like to have DataTemplates such that I can say: These are the DataTemplates for use in a TreeView These are the DataTemplates to use when showing the summary of an object These are the DataTemplates to use when showing details The only way I've seen to be able to do this is to create a DataTemplateSelector ...

DataTemplate.DataType=Collection<Entity> ?

Is there a way to create a data template that handles a list of items? I have Contact.Phones (EntityCollection) and I want the data template to handle the list - add remove edit etc. Is there a way to set the DataType property of the DataTemplate to generic EntityCollection? ...

Access to DataTemplate Control of WPF Toolkit DataGridCell at Runtime, How?

I have a DataGrid defined with WPF Toolkit. The CellEditingTemplate of this DataGrid is associated at runtime with a custom function that build a FrameworkElementFactory element. Now I have to access to control that is inserted inside DataTemplate of CellEditingTempleta, but I do not know how to do. On web I found a useful ListView Hel...