FAQ Database Discussion Community


WPF ItemsControl and Togglebuttons weird behaviour

c#,wpf,itemscontrol,togglebutton
I've been working on a WPF application but encountered some weird behaviour when using ItemsControl to display a list of togglebuttons with binding. It works just fine when it is displaying a collection of 1 element, but when I have two elements it behaves very strange. It will not show...

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,...

ContentPresenter in ItemControl.ItemTemplate to show displaymemberpath of itemscontrol

c#,wpf,itemscontrol,contentpresenter
I want to know is there anyway to put contentpresenter in itemtemplate of an itemscontrol to display my data. I don't want hard code binding like Text="{Binding username}" cause I am building a custom control, I think ContentPresenter is what I want. But after I tried using contentpresenter, it give...

WPF nested itemscontrol EventToCommand binding path error

wpf,mvvm,binding,nested,itemscontrol
I have a problem with my WPF bindings inside an itemscontrol. The following error occurs System.Windows.Data Error: 40 : BindingExpression path error: 'MovieImageClick' property not found on 'object' ''RelativeSource' (HashCode=56697999)'. BindingExpression:Path=MovieImageClick; DataItem='RelativeSource' (HashCode=56697999); target element is 'EventToCommand' (HashCode=42916613); target property is 'Command' (type 'ICommand') A simple example of the XAML:...

WPF: Disable items in bounded ItemsControl

c#,wpf,itemscontrol,stackpanel
I'm working on a WPF page with the following: <ItemsControl ItemsSource="{Binding Peopl.PhoneNums}" x:Name="PhoneList"> <ItemsControl.ItemTemplate> <DataTemplate> <Grid> <StackPanel Orientation="Horizontal" Margin="0,0,0,0" x:Name="PhoneEntry"> <TextBlock Text="123-456-78901"/> <ComboBox ...> </StackPanel> </Grid> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> There can be multiple stackpanels, each with a unique phone number; in code behind, each phone...

Update ItemsControl when an item in an ObservableCollection is updated

c#,wpf,mvvm,observablecollection,itemscontrol
The Problem: You declare an ItemsControl ( or a control derived from ItemsControl) in the view. You bind the ItemsControl.ItemsSource property to an ObservableCollection in your ViewModel. Your view updates as expected when an item is added to /removed from the ObservableCollection. BUT, the view does not update when you...

Creating a dynamic expandable toolbox

c#,wpf,menu,itemscontrol,multiple-instances
I'm trying to create a dynamic expandable toolbox, like shown on the picture below. The custom control will put the different items in the base and advanced menus depending on the available space. If there's enough space to display all the items in the base menu, then the advanced menu...

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...

How to access a property path of each object in ItemsSource of a ListView from a DataTemplate

c#,xaml,templates,data-binding,itemscontrol
How can I access a property path of each object in ItemsSource of a ListView from a DataTemplate? I'm trying something like public class Person : INotifyPropertyChanged { private string _name; public string Name { get {return _name;} set { _name = value; OnPropertyChanged(); } } } public partial class...

WPF itemscontrol child alignment

wpf,mvvm,alignment,itemscontrol
I have a WPF MVVM application with an itemscontrol. The number of horizontal child items is influenced by the itemscontrol width. There is only 1 thing i haven't solved. I'm trying to align the child elements in a way that there are always centered. I have made quick pictures in...

Synchronize position of items in itemscontrol

wpf,itemscontrol
I'm trying to create a WPF control that displays two vertical "swimlanes" (Left and Right). Both Left and Right should be databound to two separate ObservableCollection in the ViewModel. ISkill has a Name property and optionally a SynchronizedWith property that basically is a reference to another ISkill object (in the...

Binding List to ItemsControl: How to refresh

wpf,binding,itemscontrol
I am binding a List to an ItemsControl. I shows up fine. But when I add a string to the list the control is not updated. I tried to raise the PropertyChanged event to force the update but that does not help. What am I doing wrong? Here is the...

WPF ItemsControl not refreshing

c#,wpf,mvvm,itemscontrol
I'm working on a WPF project. I have a class like this: public class Field { public ReservationDTO reservation { get; set; } public DelegateCommand FieldChangeCommand { get; set; } public bool Available { get; set; } } And I have a collection of it public ObservableCollection<Field> Fields { get;...

WPF DataTemplate Selector is not working

c#,wpf,itemscontrol,hierarchicaldatatemplate,datatemplateselector
I am working on a Treeview control. The items control should display a set of textbox and combobox dynamically depending on the value of the data structure. The ArgumentTypeTemplateSelector 's convert code is executed. however, no Textbox and combo is display. Please would someone kindly help. thank you. The tree...

Looping “complex” object with ItemsControl

wpf,xaml,itemscontrol
I have the following "element": public class ReportElementViewModel { public string Name { get { return _name; } set { if (_name != value) { _name = value; RaisePropertyChanged("Name"); } } } public bool IsChecked { get { return _isChecked; } set { if (_isChecked != value) { _isChecked =...

Different DataTemplates for ItemsControl WPF

wpf,itemscontrol
I have defined an ItemsControl in XAML as: <ItemsControl ItemsSource="{Binding MyCollection}" AlternationCount="{Binding RelativeSource={RelativeSource Self}, Path=Items.Count}"> <ItemsControl.Resources> <DataTemplate x:Key="TemplateOne"> <Button Content="{Binding RelativeSource={RelativeSource Self}, Path=(ItemsControl.AlternationIndex)}" Style="{StaticResource StyleOne}"/> </DataTemplate> <DataTemplate x:Key="TemplateTwo"> <Button Content="{Binding RelativeSource={RelativeSource Self},...

WPF : How to bind Button's visibility inside ListBox ItemsControl using selecteditem information ?

c#,wpf,listbox,itemscontrol,selecteditem
I have a list box binds to a ObservableCollection of Items. Each listboxItem contains a few textblocks and a few buttons. I would like to show the buttons inside the listboxItem only when the listbox item is selected or hightlight. If the listbox item is not highlighted, the button should...

Why do ScrollViewer scroll to ItemsControl when an Item is removed?

wpf,.net-3.5,scrollviewer,itemscontrol
ScrollViewer seems to have a default behavior that makes it scroll to an ItemsControl when this ItemsControl's Items lose an element. Take this example: <ScrollViewer> <ItemsControl> <TextBlock Text="Something"/> <TextBlock Text="Something"/> <TextBlock Text="Something"/> <TextBlock Text="Something"/> <TextBlock Text="Something"/> <TextBlock Text="Something"/> <TextBlock Text="Something"/> <TextBlock Text="Something"/> <TextBlock Text="Something"/> <TextBlock...

WPF ItemsControl element DataTrigger doesn`t fire after data changes

c#,wpf,colors,itemscontrol,datatrigger
I`ve got such an issue: my datatrigger doesnt change color after binded data changes. Datatrigger is on TextBlock which is ElemntTenplate for ItemsControl. My Xaml: <Grid> <Grid.RowDefinitions> <RowDefinition ></RowDefinition> <RowDefinition Height="3*"></RowDefinition> </Grid.RowDefinitions> <Grid> <Grid.RowDefinitions> <RowDefinition ></RowDefinition> <RowDefinition ></RowDefinition> </Grid.RowDefinitions> <Grid.ColumnDefinitions>...

How to check where a Panel's Children come from?

wpf,panel,itemscontrol
I created a custom Panel, within which I need to check whether its Children are managed by manipulating the collection manually, or whether the panel is used as ItemsPanel for an ItemsControl. This to prevent the following exception from being thrown when trying to manipulate Children. Cannot explicitly modify Children...