WPF ListBox with a ListBox – UI Virtualization and Scrolling

It is possible to achieve smooth scrolling VirtualizingStackPanels in WPF 4.0 without sacrificing virtualization if you’re prepared to use reflection to access private functionality of the VirtualizingStackPanel. All you have to do is set the private IsPixelBased property of the VirtualizingStackPanel to true. Note that in .Net 4.5 there’s no need for this hack as … Read more

Bind multiple ComboBox to a single List – Issue: When I select an item, all combo boxes change

Since you are binding all combo boxes to the same data source – a single list – they are using a single BindingManagerBase. So when you choose an item from one of combo boxes, the current Position of the shared binding manager base changes and all combo boxes goes to that position of their shared … Read more

Selecting a Textbox Item in a Listbox does not change the selected item of the listbox

We use the following style to set a PreviewGotKeyboardFocus which handles all events of TextBox control and ComboBoxes and such: <ListView.ItemContainerStyle> <Style TargetType=”ListViewItem”> <EventSetter Event=”PreviewGotKeyboardFocus” Handler=”SelectCurrentItem”/> </Style> </ListView.ItemContainerStyle> And then we select the row in code behind: protected void SelectCurrentItem(object sender, KeyboardFocusChangedEventArgs e) { ListViewItem item = (ListViewItem) sender; item.IsSelected = true; }

ItemContainerGenerator.ContainerFromItem() returns null?

I found something that worked better for my case in this StackOverflow question: Get row in datagrid By putting in UpdateLayout and a ScrollIntoView calls before calling ContainerFromItem or ContainerFromIndex, you cause that part of the DataGrid to be realized which makes it possible for it return a value for ContainerFromItem/ContainerFromIndex: dataGrid.UpdateLayout(); dataGrid.ScrollIntoView(dataGrid.Items[index]); var row … Read more

ListBox items return string, when DataTemplate is Button

You need FrameworkTemplate.FindName Method (String, FrameworkElement) for this purpose: private childItem FindVisualChild<childItem>(DependencyObject obj) where childItem : DependencyObject { for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++) { DependencyObject child = VisualTreeHelper.GetChild(obj, i); if (child != null && child is childItem) return (childItem)child; else { childItem childOfChild = FindVisualChild<childItem>(child); if (childOfChild != null) return childOfChild; } … Read more

WPF Binding a ListBox to an enum, displaying the Description Attribute

Yes, it is possible. This will do it. Say we have the enum public enum MyEnum { [Description(“MyEnum1 Description”)] MyEnum1, [Description(“MyEnum2 Description”)] MyEnum2, [Description(“MyEnum3 Description”)] MyEnum3 } Then we can use the ObjectDataProvider as xmlns:MyEnumerations=”clr-namespace:MyEnumerations” <ObjectDataProvider MethodName=”GetValues” ObjectType=”{x:Type sys:Enum}” x:Key=”MyEnumValues”> <ObjectDataProvider.MethodParameters> <x:Type TypeName=”MyEnumerations:MyEnum” /> </ObjectDataProvider.MethodParameters> </ObjectDataProvider> And for the ListBox we set the ItemsSource to … Read more

Databinding to List – See changes of data source in ListBox, ComboBox

In Windows Forms, in a scenario that you want to see changes of data source in the bound list control, like ComboBox, ListBox or DataGridView (complex two-way data binding), you should use a class that implements IBindingList interface as DataSource of data binding. The most suitable implementation is BindingList<T>. This way each add/remove in the … Read more

tech