FAQ Database Discussion Community


TwoWay Binding is not working if Binding is changed from DataTrigger

wpf,datatemplate,datatrigger,2-way-object-databinding
I have the following DataTemplate for my Tool Bar Items: <DataTemplate DataType="{x:Type viewModels:PopupContextActionViewModel}"> <Grid> <ToggleButton Name="ToggleButton"> <ContentControl Template="{Binding Icon, Converter={StaticResource NameToResourceConverter}}" Margin="5" /> </ToggleButton> <Popup Name="ContextActionPopup" StaysOpen="False" AllowsTransparency="True" IsOpen="{Binding ElementName=ToggleButton, Path=IsChecked, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"> <Border...

ObservableCollection.CollectionChanged does not select the correct DataTemplate on ToolBar

c#,wpf,datatemplate
I have a ToolBar with 3 DataTemplates for my Items: <ToolBar ItemsSource="{Binding ContextActions}" Background="Transparent" ToolBarTray.IsLocked="True"> <ToolBar.Resources> <DataTemplate DataType="{x:Type viewModels:SimpleContextActionViewModel}"> <Button Command="{Binding ActionCommand}" Style="{StaticResource ToolBarButtonStyle}" ToolTip="{userInterface:Translation Binding={Binding ToolTip}}"> <ContentControl Template="{Binding Icon,Converter={StaticResource NameToResourceConverter}}" Margin="5"...

WPF Specifying HierarchicalDataTemplate for Interface

wpf,data-binding,interface,datatemplate
I've found a really strange quirk in WPF. If I specify a DataTemplate for an interface, it will work if defined inside an ItemsControl.ItemTemplate, but will not work if defined inside ItemsControl.Resrouces. Concrete example: I have a tree structure I want to represent. All items in the tree implement IHardware,...

WPF DatePicker DisplayDate binding does not work inside DataGrid/DataTemplate/ControlTemplate

wpf,datagrid,datepicker,datatemplate,controltemplate
It seems wpf DatePicker's DisplayDate binding does not work when datepiceker is inside datagrid or datatemplate. Here is the sample code <DataGrid x:Name="grid" AutoGenerateColumns="False" IsReadOnly="True"> <DataGrid.Columns> <DataGridTemplateColumn Header="StartDate" MinWidth="155"> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <DatePicker SelectedDate="{Binding Path=StartDate}" /> </DataTemplate> </DataGridTemplateColumn.CellTemplate> </DataGridTemplateColumn>...

In Silverlight 5, how do I bind each DataGrid's row background color to one of its bound item's properties?

datagrid,datatemplate,silverlight-5.0,controltemplate,datatrigger
Please note that this question is specific to Silverlight 5. There are lots of similar questions floating around, but often they are about WPF or previous Silverlight versions. Others target Silverlight 5, but are about controls other than DataGrid. I have been unable to find an existing question that...

Better way to handle navigation between ContentControls in WPF MVVM?

c#,wpf,mvvm,navigation,datatemplate
I am currently developing a C# WPF application and am trying to follow the MVVM design pattern. The way it is working now, is I am using a ContentControl in my main window and binding it to the CurrentViewModel, and declaring in App.xaml my datatemplates. When I want to change...

Is it possible to define a TreeView hierarchical view template for a 'plain' collection?

c#,wpf,mvvm,treeview,datatemplate
I have my model classes that look like this: class Base { public string Name { get; set; } } class Item : Base { ... } class Group : Base { public List<Base> GroupItems { get; private set; } } Then, I have a view model with an Items...

Overlapping Items in WPF ItemsControl

c#,wpf,xaml,user-interface,datatemplate
I am having a problem with DataTemplates used in a WPF ItemsControl. I want to be able to "bring forward" any of the items in the list so that they are on top of everything else in the list, but haven't had any luck. Here's a simple example that illustrates...

WPF ListBox.ItemsSource = ObservableCollection - takes a long time to load

c#,wpf,listbox,datatemplate,stopwatch
I've got code like this: (loading Collection of custom objects into memory and into ListBox item) public class Product : INotifyPropertyChanged { // these four doesn't matter, just Product's simple data public string nDB_No { get; set; } public string fdGrp_Cd { get; set; } public string long_Desc { get;...

ListView ignoring DataTemplates when using a ControlTemplate

wpf,listview,datatemplate
I try to implement a multi column ListView. Everything worked just fine until I tried to style the mouseover- and selection-look of the list view items. I therefore created a ControlTemplate (see XAML below). When I use the ControlTemplate, the DataTemplates for the columns are ignored. When I remove the...

ListView SelectionChanged won't update when enclosed TextBox clicked

wpf,listview,datatemplate,selectionchanged,selecteditemchanged
I have a list view with a gridview. The gridview second column contains textboxes (and in case this is relevant to this particular problem, the textboxes are rendered by a datatemplate). I want the listview SelectedItem to update when the user clicks in the textbox to type and reflect the...

Getting children of DataTemplate throws “catastrophic failure” (WP 8.1)

c#,xaml,windows-phone-8,windows-phone,datatemplate
I am attempting to create a Windows Phone 8.1 application. Whenever I attempt to get the children of a DataTemplate (which is necessary because they are embedded in a ListView), I get an Exception that details a Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED)) I have made a very simple...

ItemsControl ignores DataTemplates in Resources

c#,wpf,xaml,datatemplate,itemscontrol
I want to bind a collection of multiple types to an ItemsControl being displayed in a canvas. My code so far is the following: <ItemsControl ItemsSource="{Binding Path=Objects}"> <ItemsControl.Resources> <DataTemplate DataType="self:CalibrationRectangle"> <Rectangle Fill="{Binding Path=Color, Converter={StaticResource ColorToBrushConverter}}" Width="{Binding Width}" Height="{Binding Height}" /> </DataTemplate> <DataTemplate DataType="self:PolygonVM"> <Polygon Fill="{Binding Path=Color,...

Windows Phone 8.1 App dont see DataType property in DataTemplate

c#,xaml,windows-phone-8.1,datatemplate
I created new Windows Phone 8.1 project and when I try to set DataType , vs2013 give me in editor error: The property 'DataType' was not found in type 'DataTemplate'. In WPF application I dont have this problem. How to fix it? This is my MainPage.xml: <Page x:Class="App6.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"...

Microsoft WPF Map Control - InvalidOperationException - “Cannot perform this operation while dispatcher processing is suspended.”

wpf,datatemplate,bing-maps,invalidoperationexception
I have a WPF application built on .NET 4.5. The latest version of the map control (version 1.0.1.0) is causing an issue if it is used within a datatemplate. This does not happen with the previous version I was using from NuGet (version 1.0.0.0). It is easy to reproduce the...

Button DataTemplate width too large

xaml,windows-phone-8.1,datatemplate,blend,visual-studio-2015
I created a DataTemplate from a Button and put the MinWidth and MinHeight to 0. I set the width and height to 75 on the Grid of the DataTemplate. The grid has a border and it's MinWidth and MinHeight are also both set to 0. The width and height of...

Items Control and Items Template within another Items Control/Data Template

c#,arrays,wpf,datatemplate,itemscontrol
I am trying to display an Items Control which contains another Items control representing an array of LED indicators. The LED array and all the other data in the main Item Control is bound to an Observable collection. I can't get the LED array to display. I also know I'm...

Silverlight: Get first TextBox in DataTemplate

vb.net,silverlight,datatemplate,children
So far I have looked at several questions and answers for how to get a TextBox within a DataTemplate, but none of it is working for me. I have xaml like so (minimal example). The data template is in my section for static resources, and the ItemsControl is in the...

WPF: Defining “Templates” for Elements Not Inherited From Control

c#,wpf,datatemplate,controltemplate,flowdocument
In this post I tried to find a way to re-template the contents of a FlowDocument. I've done several hours of research, and eventually come to this documentation on Control.Template property: The ControlTemplate specifies the appearance of a Control; if a Control does not have a ControlTemplate, the Control will...

How to Show percentage in WPF datagridProgressbarcolumn along with progress?

c#,wpf,wpfdatagrid,datatemplate,datarow
I am used the below codes in datagridtemplateprogressbarcolumn and its working fine progress But how to give the percentage along with this below code. The below code is working for progress only,How to show percentage along with that code. In xaml file:- <DataGridTemplateColumn Header="Progress" Width="*" Visibility="Visible"> <DataGridTemplateColumn.CellTemplate> <DataTemplate> <ProgressBar Value="{Binding...

Binding DataGrid Within A DataTemplate of ItemsControl

wpf,data-binding,datagrid,datatemplate
I have a strange issue occurring with the binding I'm trying to set up. I have an ItemsControl which I'm using to render a WrapPanel which contains a DataGrid for its DataTemplate. Ultimately I want to use the WrapPanel to show one DataGrid for each item in the list that...

ComboBox DataTemplate in WPF datagrid with binding not initialized

wpf,binding,combobox,datatemplate
I have a binding list of Models and a DataGrid. Value can be of couple of data types (bool, double). public class Model { public object Value { get; set; } } public void Initialize() { var models = new BindingList<Model>(); models.Add(new Model(){ Value = "hello"}); models.Add(new Model(){Value=true}); signals.ItemsSource =...

One out of two buttons using same ControlTemplate does not animate

wpf,datatemplate,controltemplate,visualstatemanager
I have a ListView that uses a DataTemplate to render out each item, with each item having an Edit and Remove button. The two buttons are templated so that they use a Path to display an icon, and animate with a storyboard when the mouse over happens. The animation changes...

WPF: Access parent DataTemplate from DataContext

wpf,xaml,datatemplate,datacontext
I have the below situation: <DataTemplate DataType="{x:Type tra:Presenter}"> <DockPanel> <GroupBox> <ie:DifferentControl DataContext="{Binding LocationSelectorPresenter}" Visibility="{Binding PropertyOnTraPresenter, Converter={StaticResource boolToVis}}"/> </GroupBox> </DockPanel> </DataTemplate> How do I access a property on the DataTemplate's datatype, from something that has it's own DataContext? I've attempted using FindAncestor as below, but with no luck. (This came from...

WPF DataTemplate on ListView to visualize different kinds of user controls

wpf,listview,datatemplate
I have a ListView which I want to present different kinds of user controls, depending on which view model is set for the list view item. In xaml: <ListView ItemsSource="{Binding Items}"> <ListView.Resources> <DataTemplate DataType="{x:Type viewModels:LabelledTextViewModel}"> <controls:LabelledTextBox/> </DataTemplate> <DataTemplate DataType="{x:Type viewModels:FolderChooserViewModel}"> <standardControls:FolderChooser/> </DataTemplate> </ListView.Resources> </ListView> Now this...

Is it possible to pass current DataContext as ContructorParameter of ObjectDataProvider?

c#,wpf,datatemplate,datacontext,objectdataprovider
It would be very useful to pass DataContext as parameter for DataTemplate: <DataTemplate> <DataTemplate.Resources> <ObjectDataProvider x:Key="ServiceDataProvider" ObjectType="{x:Type control:ServiceLayout}"> <ObjectDataProvider.ConstructorParameters> /*here could be DataContext..but how?*/ </ObjectDataProvider.ConstructorParameters> </ObjectDataProvider> </DataTemplate.Resources> <ContentPresenter Content="{Binding Source={StaticResource ServiceDataProvider}}" />...

DataTemplate doesn't seem to be binding

wpf,xaml,datatemplate,itemssource
I'm filling a ListBox with items from a bound model. While testing I had this: <ListBox x:Name="SettingsHolder" Margin="5,8,5,5" ItemsSource="{Binding AllSettingItems}" Height="380" DisplayMemberPath="Display"/> By binding directly to a member of item objects in ItemsSource, I was able to see I was loading the list box properly. In fact, the 'Display' member...

Dynamically set image of each node

wpf,xaml,treeview,datatemplate,datatrigger
So I have 3 levels of nodes in my TreeView: A single Root Node (should display Image1.png) Some second level nodes (should display Image2.png) Each second level node has some third-level nodes (should display Image3.png) I'm trying to use a DataTemplate to dynamically assign the display image to each node,...

Difference between HierachicalDataTemplate and DataTemplate with ItemsControl

c#,wpf,xaml,mvvm,datatemplate
I would like to know the real differences between a HierarchicalDataTemplate and a DataTemplate with an Itemcontrol within this DataTemplate. Here is some sample code: MainWindow.xaml <Window x:Class="WpfApplication2.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:test="clr-namespace:WpfApplication2" Title="MainWindow" Height="350" Width="525"> <Window.Resources> <DataTemplate DataType="{x:Type test:TeamViewModel}">...