Sort a wpf datagrid programmatically

voo’s solution was not working for me, ItemsSource was null, most likely because it was not directly set, but bound. All other solutions I found here at StackOverflow were dealing with sorting the Model only, but the DataGrid header was not reflecting to the sort. Here’s a proper solution based on the incomplete script here: … Read more

How do you pass parameters from xaml?

Your constructor: public ClockControl(String city) { InitializeComponent(); this.initController(); //… } First of all, if you want to use ClockControl from XAML, then you need a default constructor, means a constructor which doesn’t take any parameter. So the above constructor is not going to work. I would suggest you to define a property with name City, … Read more

How can I tell my DataTemplate to bind to a property in the PARENT ViewModel?

The answer is this: <DataTemplate x:Key=”CodeGenerationMenuTemplate”> <MenuItem Header=”{Binding Title}” Command=”{Binding DataContext.SwitchPageCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Menu}}}” CommandParameter=”{Binding Title}”/> </DataTemplate> I just saw that Nir had given me the syntax to solve the above issue on this question: What is the best way in MVVM to build a menu that displays various pages?.

How to scroll to the bottom of a ScrollViewer automatically with Xaml and binding?

You can either create an attached property or a behavior to achieve what you want without using code behind. Either way you will still need to write some code. Here is an example of using attached property. Attached Property public static class Helper { public static bool GetAutoScroll(DependencyObject obj) { return (bool)obj.GetValue(AutoScrollProperty); } public static … Read more