Best way to databind a group of radiobuttons in WinForms

Following is a generic RadioGroupBox implementation in the spirit of ArielBH’s suggestion (some code borrowed from Jay Andrew Allen’s RadioPanel). Just add RadioButtons to it, set their tags to different integers and bind to the ‘Selected’ property. public class RadioGroupBox : GroupBox { public event EventHandler SelectedChanged = delegate { }; int _selected; public int … Read more

PropertyChanged for indexer property

According to this blog entry, you have to use “Item[]”. Item being the name of the property generated by the compiler when using an indexer. If you want to be explicit, you can decorate the indexer property with an IndexerName attribute. That would make the code look like: public class IndexerProvider : INotifyPropertyChanged { [IndexerName … Read more

Why can’t I select a null value in a ComboBox?

Well I recently ran into the same problem with null value for ComboBox. I’ve solved it by using two converters: For ItemsSource property: it replaces null values in the collection by any value passed inside converter’s parameter: class EnumerableNullReplaceConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var collection … Read more

How do I bind a List to a WPF DataGrid?

if you do not expect that your list will be recreated then you can use the same approach as you’ve used for Asp.Net (instead of DataSource this property in WPF is usually named ItemsSource): this.dataGrid1.ItemsSource = list; But if you would like to replace your list with new collection instance then you should consider using … Read more

WPF ComboBox performance problems by binding a large collections

According to this blog: http://vbcity.com/blogs/xtab/archive/2009/12/15/wpf-using-a-virtualizingstackpanel-to-improve-combobox-performance.aspx I’ve tested it with this code: <ComboBox Name=”cbBlah” ItemsSource=”{Binding}”> <ComboBox.ItemsPanel> <ItemsPanelTemplate> <VirtualizingStackPanel /> </ItemsPanelTemplate> </ComboBox.ItemsPanel> </ComboBox> It works fine for first time and next times. It’s not necessary to code these lines: <VirtualizingStackPanel VirtualizingStackPanel.IsVirtualizing=”True” VirtualizingStackPanel.VirtualizationMode=”Recycling” />

DataGridView Cascading/Dependent ComboBox Columns

To have dependent (cascading or master/slave) ComboBox columns in DataGridView, you can follow this steps: Set DataSource of slave column to all available values. Goal: Here the goal is prevent rendering errors at first load, so all slave combo boxes can show value correctly. Hanlde EditingControlShowing event of the grid and check if the current … Read more

WPF TwoWay Binding to a static class Property

Use the static property binding syntax (which is, as far as I know, available since WPF 4.5): <TextBox Text=”{Binding Path=(engine:ProjectData.Username)}”/> No need to set Mode=”TwoWay”, as that is the default for the TextBox.Text property anyway. Although not explicitly asked for, you may also want to implement property change notification. See this answer for how to … Read more