data-binding
When is it worth using a BindingSource?
Pretty old question. Wonder why anyone hasn’t answered it till now. OK, I’ll try and share things from my experience. A BindingSource is more than just a way to bind controls to collections. After having worked in WinForms for over a decade, the best features of a BindingSource that I like the most include: Binding … Read more
ItemsControl with multiple DataTemplates for a viewmodel
You can create multiple ObservableCollections and then bind your ItemsSource to a CompositeCollection which joins those collections. Then in your XAML you can create different DataTemplates for the respective types using the DataType property which like styles gets automatically applied if it is placed in the resources. (You can also create the composite in XAML … Read more
WPF Sentinel objects and how to check for an internal type
In .NET 4.5, you can now compare against BindingOperations.DisconnectedSource.
Two-way binding in WPF
Most probably you’re trying to bind to a .net CLR property instead of a WPF dependencyProperty (which provides Change Notification in addition to some other things). For normal CLR property, you’d need to implement INotifyPropertyChanged and force update on the textbox in the event handler for PropertyChanged. So make your object with the property implement … Read more
How to see design-time data-binding in XAML editor (it works in runtime)?
Make sure that you have these definitions at the root tag of your xaml file (in your case the Window tag): xmlns:mc=”http://schemas.openxmlformats.org/markup-compatibility/2006″ xmlns:d=”http://schemas.microsoft.com/expression/blend/2008″ mc:Ignorable=”d” Then, anywhere in the xaml (including the root tag) you can add this: d:DataContext=”{d:DesignInstance myNamespace:MyViewModel, IsDesignTimeCreatable=True}” Now you just need to make sure that you initialize the values in a constructor … Read more
SelectedValue which is invalid because it does not exist in the list of items
Apparently the solution I posted wasn’t entirely effective… Eventually in my application I changed to this: listOrgs.Items.Clear(); listOrgs.SelectedIndex = -1; listOrgs.SelectedValue = null; listOrgs.ClearSelection(); // Clears the selection to avoid the exception (only one of these should be enough but in my application I needed all..) listOrgs.DataSource = new Organization().DTListAll(SiteID); listOrgs.DataTextField = “OrganizationName”; listOrgs.DataValueField = … Read more