单击内部的按钮时,使列表框处于选中状态 [英] make listbox selected when click button inside

查看:142
本文介绍了单击内部的按钮时,使列表框处于选中状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列表框,它的项目包含button,textbllock.我已成功将按钮的命令绑定到Viewmodel,并在该listboxitem中单击button时获得了listboxitem的索引.现在的问题是,当我单击listboxitem内的按钮时,没有选择listboxitem.

仅当我单击按钮框和文本块外部的listboxitem区域时,才选择listboxitem.

当我单击列表框项目中的按钮时,如何使列表框项目处于选中状态?

I have a listbox, its items contain button, textbllock .I successfully binded the command of button to Viewmodel,and get index of listboxitem when click button inside that listboxitem. now the problem is when I click the button inside listboxitem,the listboxitem did not selected.

listboxitem is selected only when I click the area of listboxitem outside button and textblock.

how can I make listboxitem selected when I click button inside this listboxitem ? is there any simple solution to do that?

推荐答案

您可以在视图模型中将列表框的SelectedValue绑定到属性.
当您选择按钮时,您将提交带有列表框项目有效负载的委托命令.然后可以将此项目放置到绑定的selectedvalue的viewmodel属性中.
you could, in your viewmodel bind the SelectedValue of the listbox to a property.

When you select the button you would file a delegate command with a payload of the listbox item. This item can then be placed into the viewmodel property for the bound selectedvalue.


这篇关于单击内部的按钮时,使列表框处于选中状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆