WPF MVVM: how to bind GridViewColumn to ViewModel-Collection?

The Columns property is not a dependency property, so you can’t bind it. However, it might be possible to create an attached property that you could bind to a collection in your ViewModel. This attached property would then create the columns for you. UPDATE OK, here’s a basic implementation… Attached properties using System.Collections.Generic; using System.Collections.Specialized; … Read more

How to access a control from a ContextMenu menuitem via the visual tree?

This is happening because DataContext=”{Binding PlacementTarget,… binding would set the button as MenuItems DataContext but that won’t add the ContextMenu to the VisualTree of your window and that’s why ElementName binding’s won’t work. A simple workaround to use ElementName bindings is to add this in your Window/UserControl’s code-behind: NameScope.SetNameScope(contextMenuName, NameScope.GetNameScope(this)); Another solution is to do … Read more

Maintain state of a dynamic list of checkboxes in ASP.NET MVC

I got it working after much playing around with the various different approaches. In the view: <%string[] PostFeatures = Request.Form.GetValues(“Features”);%> <% foreach (var Feature in (ViewData[“AllPropertyFeatures”] as IEnumerable<MySolution.Models.PropertyFeature>)) { %> <input type=”checkbox” name=”Features” id=”Feature<%=Feature.PropertyFeatureID.ToString()%>” value=”<%=Feature.PropertyFeatureID%>” <%if(PostFeatures!=null) { if(PostFeatures.Contains(Feature.PropertyFeatureID.ToString())) { Response.Write(“checked=\”checked\””); } } %> /> <label for=”Feature<%=Feature.PropertyFeatureID%>”> <%=Feature.Description%></label> <% } %> In the receiving controller method: … Read more

WPF ViewModel Commands CanExecute issue

To complete Will’s answer, here’s a “standard” implementation of the CanExecuteChanged event : public event EventHandler CanExecuteChanged { add { CommandManager.RequerySuggested += value; } remove { CommandManager.RequerySuggested -= value; } } (from Josh Smith’s RelayCommand class) By the way, you should probably consider using RelayCommand or DelegateCommand : you’ll quickly get tired of creating new … Read more

WPF DataGrid : CanContentScroll property causing odd behavior

You are encountering the differences between physical scrolling and logical scrolling. As you have discovered, each has its tradeoffs. Physical scrolling Physical scrolling (CanContentScroll=false) just goes by pixels, so: The viewport always represents exactly the same portion of your scroll extent, giving you a smooth scrolling experience, and but The entire contents of the DataGrid … Read more