Click here to Skip to main content
15,867,308 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am new to UWP technology as well as new in MVVM too. I have multiple checkboxes on my page. I want to save/update data if my checkbox is checked or unchecked. I don't know how to use Command, Checked Event or Unchecked Event of checkbox in UWP using MVVM pattern.

What I have tried:

A list of the checkboxes is inside the ListView and the ListView is inside the usercontrol. Data binding is done.

                 <ListView
                        x:Name="listMenu"
                        MinHeight="60"
                        FontSize="14"
                        Foreground="White"
                        IsItemClickEnabled="True"
                        ItemsSource="{x:Bind Items, Mode=TwoWay}">
                        <ListView.ItemTemplate>
                            <DataTemplate>
                                <ListViewItem
                                    Margin="0"
                                    VerticalAlignment="Center"
                                    Style="{StaticResource SettingsChangeLanguageListStyle}">
                                    <StackPanel Orientation="Vertical">
                                        <CheckBox
                                            x:Name="termsOfServiceCheckBox"
                                            HorizontalAlignment="Left"
                                            VerticalAlignment="Center"
                                            Command="{Binding AreaOfExpertiseCommand}"
                                            Content="{Binding TopicName}"
                                            FontFamily="{StaticResource osRegular}"
                                            FontSize="14"
                                            Foreground="#636E7F"
                                            IsChecked="{Binding IsSelected, Mode=TwoWay}"
                                            Style="{StaticResource CheckBoxCustomStyle}" />
                                    </StackPanel>
                                </ListViewItem>
                            </DataTemplate>

                        </ListView.ItemTemplate>

                    </ListView>

Now I want to trigger Checked/Uncheck event or Command to get my current checked or unchecked CheckBox using the MVVM pattern.

I have created a Dependency Property for Command which is not executing on checking/unchecking the checkbox.

     public ICommand AreaOfExpertiseCommand
        {
            get { return (ICommand)GetValue(AreaOfExpertiseCommandProperty); }
            set { SetValue(AreaOfExpertiseCommandProperty, value); }
        }

     public static readonly DependencyProperty AreaOfExpertiseCommandProperty = DependencyProperty.Register(nameof(AreaOfExpertiseCommand), typeof(ICommand), typeof(AreaOfExpertiseUserControl), new PropertyMetadata(null));
    
ViewModel.cs :

     public ICommand AreaOfExpertiseCommand => new RelayCommand(UpdateAreaOfExpertiseAsync);

     private void UpdateAreaOfExpertiseAsync()
     {

     }

Any help will be appreciated..  
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900