Как вызвать отмеченные / непроверенные события или команду флажка в UWP, используя MVVM - PullRequest
0 голосов
/ 31 марта 2020

Я новичок в технологии UWP, а также в MVVM. У меня есть несколько флажков на моей странице. См. Ниже:

enter image description here

Список флажков находится внутри ListView, а ListView находится внутри usercontrol. Привязка данных завершена.

             <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>

Теперь я хочу вызвать событие Checked / Uncheck или команду для получения моего текущего установленного или не отмеченного CheckBox с использованием шаблона MVVM.

Я создал свойство зависимости для команды, которая не выполняется при установке / снятии флажка.

 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()
 {

 }

Любая помощь будет оценена ..

...