获取选中的复选框值 mvvm light wpf

发布于 2024-09-12 15:28:36 字数 752 浏览 2 评论 0原文

我有一个用户控件,其中将主要类别显示为数据库中的按钮。通过单击“主类别”按钮,将打开一个新的用户控件,其中单击了相应类别中的项目列表。我使用 TexbBlock 在 xaml 中绑定该类别的项目名称,并且还显示每个要选择的项目的复选框。我想在选择复选框并单击“完成”按钮后获取它们的值。复选框值应该是数据库中的项目 ID。如何获取选定的复选框值。

这是相同的 xaml:

                        <!--<Button  Content="{Binding CategoryName}" Margin="5"/>-->
                        <TextBlock Text="{Binding SubCategoryName}" HorizontalAlignment="Center" VerticalAlignment="Top"  />                         
                        <CheckBox Grid.Row="3" />
                    </StackPanel>
                </DataTemplate>
            </ItemsControl.ItemTemplate>

请建议?

谢谢,

塔伦

I have one usercontrol where am showing the main categories as buttons from the database. By clicking on Main Category button, a new user control is getting opened with list of items in that respective category clicked. I am binding the Item Names of that category in a xaml using TexbBlock and also am showing the checkboxes with each Items to select. I want to get the values of checkboxes after selecting them and clicking on the Done button. Checkbox values should be the items ID in the database. How to get the selected checkbox values.

Here is the xaml for the same:

                        <!--<Button  Content="{Binding CategoryName}" Margin="5"/>-->
                        <TextBlock Text="{Binding SubCategoryName}" HorizontalAlignment="Center" VerticalAlignment="Top"  />                         
                        <CheckBox Grid.Row="3" />
                    </StackPanel>
                </DataTemplate>
            </ItemsControl.ItemTemplate>

Kindly suggest?

Thanks,

Tarun

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无所的.畏惧 2024-09-19 15:28:36

我认为你需要做的是,在 ViewModel 上有一个名为“Checked”(或类似的东西)的布尔属性,然后将其绑定到你的复选框。

IsChecked="{Binding Checked, Mode=TwoWay}"

“Mode=TwoWay”意味着当你检查复选框时,绑定将自动更新 ViewModel 上的属性。

希望这有帮助

I think what you need to do, is have a boolean property on you ViewModel that is called "Checked" (or something similar) then bind it to your checkbox

IsChecked="{Binding Checked, Mode=TwoWay}"

The "Mode=TwoWay" will mean that when you Check the CheckBox, the binding will automatically update the property on your ViewModel.

Hope this helps

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文