.NET/C# Binding Custom DependencyProperty to ViewModel Property

Consider the following scenario: UserControl with a custom DependencyProperty ViewModel with an exposed property (using INotifyPropertyChanged) Goal: create two-way data binding between these two properties (i.e., ViewModel property gets updated if DependencyProperty changes and vice versa) ViewModel (implements INotifyPropertyChanged): private…

Read More

.NET/C# Get First Visible Item of a ListBox

This is some code to get the first visible item in a WPF ListBox whenever the user scrolled. In XAML: <ListBox Name="MyListBox" ItemsSource="{Binding SomeCollection}" ScrollViewer.ScrollChanged="ScrollChanged"/> In the code-behind: private void ScrollChanged(object sender, ScrollChangedEventArgs e) { VirtualizingStackPanel panel = FindVisualChild<VirtualizingStackPanel>(MyListBox); if…

Read More