I am developing a UWP application with the Mvvm Light and Behaviors SDKs. I defined a multi-user ListView:
<ListView x:Name="MembersToInviteList" IsMultiSelectCheckBoxEnabled="True" SelectionMode="Multiple" ItemsSource="{Binding Contacts}" ItemTemplate="{StaticResource MemberTemplate}"> </ListView>
I would like the button to snap to the MVVM-Light RelayCommand to get a list with the selected items:
<Button Command="{Binding AddMembersToEvent}" CommandParameter="{Binding ElementName=MembersToInviteList, Path=SelectedItems}" Content="Ok"/>
RelayCommand (from MVVM-Light structure):
private RelayCommand<object> _addMembersToEvent; public RelayCommand<object> AddMembersToEvent { get { return _addMembersToEvent ?? (_addMembersToEvent = new RelayCommand<object>( (selectedMembers) => {
I set a breakpoint inside the command and I noticed that selectedMembers is always null , although I select various elements. At the console output, I do not see any binding errors or anything else.
Also, if I pass the entire list as CommandParameter, and I set a breakpoint in the command definition, I noticed that I cannot access the values of SelectedItems or SelecteRanges.
<DataTemplate x:Name="MemberTemplate"> <Viewbox MaxWidth="250"> <Grid Width="250" Margin="5, 5, 5, 5" Background="{StaticResource MyLightGray}" BorderBrush="{StaticResource ShadowColor}" BorderThickness="0, 0, 0, 1" CornerRadius="4" Padding="5"> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="1*" /> </Grid.ColumnDefinitions> <Grid Grid.Column="0" Width="45" Height="45" Margin="5,0,5,0" VerticalAlignment="Center" CornerRadius="50"> <Grid.Background> <ImageBrush AlignmentX="Center" AlignmentY="Center" ImageSource="{Binding Image.Url, Converter={StaticResource NullGroupImagePlaceholderConverter}}" Stretch="UniformToFill" /> </Grid.Background> </Grid> <TextBlock Grid.Column="1" Margin="3" VerticalAlignment="Center" Foreground="{StaticResource ForegroundTextOverBodyColor}" Style="{StaticResource LightText}" Text="{Binding Alias}" /> </Grid> </Viewbox> </DataTemplate>
What reason? How can I get such a list?
c # uwp binding xaml mvvm-light
Francesco B.
source share