如何在下一个窗口中传递选定的单选按钮并在 WPF 中显示为选定的?

发布于 2024-09-06 09:29:32 字数 461 浏览 0 评论 0原文

我有一个带有数据网格 dgSample 的 WPF 窗口。它已绑定到如下列表 lstSample:

dgSample.itemssource=lstSample;

此数据网格还有一个单选按钮列,其中我通过单击单选按钮选择一行,然后,在单击下一个按钮后我可以移至下一页。在下一页上,再次出现相同的数据网格,具有相同的单选按钮列。我想要的是,当我到达此页面时,我希望在此处也选择上一页中选择的单选按钮。 我尝试通过以下方式将单选按钮列与 IsSelected 属性绑定:

IsChecked="{Binding Path IsSelected, Mode=TwoWay}"

但这不起作用。 我该怎么做才能让它发挥作用?

PS:与 xaml 相比,我更喜欢代码隐藏解决方案。

请帮忙!

I have a WPF Window with a datagrid dgSample. it has been bound to a list lstSample like this:

dgSample.itemssource=lstSample;

this datagrid also has a radio button column wherein i select one row by clicking on the radio button, and then, i can move to the next page after i click on the next button. On the next page, there is again the same datagrid, with the same radiobutton column. What I want is, that when i reach this page, i want the radio button that was selected in the previous page to be selected here as well.
I have tried binding the radiobutton column with an IsSelected Property by doing:

IsChecked="{Binding Path IsSelected, Mode=TwoWay}"

but this is not working.
What can I do to make it work?

P.S.: I prefer code-behind solution than the xaml one.

Please help !

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

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

发布评论

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

评论(1

怎会甘心 2024-09-13 09:29:32

您的模型需要实现 INotifyPropertyChanged 并调用

PropertyChanged(this, new PropertyChangedEventArgs("IsSelected"))

以使其在另一个视图中更新。

注意:如果设置了,

public event PropertyChangedEventHandler PropertyChanged = delegate { };

则不必检查是否为空。

Your model needs to implement INotifyPropertyChanged and call

PropertyChanged(this, new PropertyChangedEventArgs("IsSelected"))

to get it to update in another view.

NB: If you set

public event PropertyChangedEventHandler PropertyChanged = delegate { };

you won't have to check for null.

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