Binding SelectedItems of ListView to ViewModel

1. One way to source binding: You have to use SelectionChanged event. The easiest way is to write eventhandler in codebehind to “bind selecteditems” to viewmodel. //ViewModel public ICollectionView BusinessCollection {get; set;} public List<YourBusinessItem> SelectedObject {get; set;} //Codebehind private void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e) { var viewmodel = (ViewModel) DataContext; viewmodel.SelectedItems = listview.SelectedItems .Cast<YourBusinessItem>() .ToList(); … Read more

Twoway-bind view’s DependencyProperty to viewmodel’s property?

If you want to do it in XAML, you could try using styles to achieve that. Here’s an example: <UserControl x:Class=”MyModule.MyView” xmlns:local=”clr-namespace:MyModule”> <UserControl.Resources> <Style TargetType=”local:MyView”> <Setter Property=”MyViewProperty” Value=”{Binding MyViewModelProperty, Mode=TwoWay}”/> </Style> </UserControl.Resources> <!– content –> </UserControl> In your case both MyViewProperty and MyViewModelProperty would be named MyProperty but I used different names just to be … Read more

Binding ComboBox SelectedItem using MVVM

You seem to be unnecessarily setting properties on your ComboBox. You can remove the DisplayMemberPath and SelectedValuePath properties which have different uses. It might be an idea for you to take a look at the Difference between SelectedItem, SelectedValue and SelectedValuePath post here for an explanation of these properties. Try this: <ComboBox Name=”cbxSalesPeriods” ItemsSource=”{Binding SalesPeriods}” … Read more

Cannot find source for binding with reference ‘RelativeSource FindAncestor’ [duplicate]

DataGridTemplateColumn is not part of the visual or logical tree, and therefore has no binding ancestor (or any ancestor) so the RelativeSource doesn’t work. Instead you have to give the binding the source explicitly. <UserControl.Resources> <local:BindingProxy x:Key=”proxy” Data=”{Binding}” /> </UserControl.Resources> <DataGridTemplateColumn Visibility=”{Binding Data.IsVisible, Source={StaticResource proxy}, Converter={StaticResource BooleanToVisibilityConverter}}”> And the binding proxy. public class BindingProxy : … Read more

Entity vs Model vs View Model

The term “Model” is ambiguous. They are all models. Entity Model A class which closely resembles structure in persistence. A MemberEntity is a model which represents one member row in the Members table in a database. Not strictly tied to a Database, but some entity of some persistence. Typically has an “ID” property such as … Read more

How to change route to username after logged in?

You need to add a route to cover the case that has a user name. public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute(“{resource}.axd/{*pathInfo}”); routes.MapRoute( name: “Username_Default”, url: “{username}/{controller}/{action}/{id}”, defaults: new { controller = “Home”, action = “Index”, id = UrlParameter.Optional }, constraints: new { username = new OwinUsernameConstraint() } ); routes.MapRoute( name: “Default”, url: “{controller}/{action}/{id}”, defaults: … Read more

Setting value of Observable not updating in Knockout

Setting value of Knockout Observable / Observable Array doesn’t update You need to use the setter function to update the value of your observable / observableArray – Ex. 1 (observable) – var name=”John”; var myValue = ko.observable(); myValue(name); // Set myValue equal to John, update any subscribers var newObservable = ko.observable(‘Bill’); myValue(newObservable()); // Set myValue … Read more

tech