在运行时更改 ListBox 项目样式
我有一个列表框,其中的项目使用 ResourceDictionary 样式进行样式设置,然后将其附加到 ItemContainerStyle 属性。这使我的 ListBoxItems 的 BorderThickness 为 1。
现在我想单独折叠项目,因此我使用 Visibility.Collapsed,但由于某种原因,ItemContainerStyle 创建的边框不会随列表框项目的其余部分一起消失。就好像它在我的项目后面创建了一个层,尽管项目被折叠,但它仍然存在。
如何在运行时将 ListBoxItem(或此额外层)的 BorderThickness 设置为 0?
问候 斯克
I have a listbox where the items are styled using a ResourceDictionary style which is then attached to the ItemContainerStyle property. This gives my ListBoxItems a BorderThickness of let's say 1.
Now I want to collapse the items individually, so I use Visibility.Collapsed but for some reason the border that the ItemContainerStyle has created does not vanish with the rest of the list box item. It is as if it has created a layer behind my item and this remains despite the item being collapsed.
How do I set the ListBoxItem's (or this extra layer's) BorderThickness to 0 at run-time?
Regards
sk
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试使用自定义触发器:
显然改变你的边框厚度值,但这应该可以解决问题(或非常接近于此的东西)
try using a custom triggers:
Obviously change your border thickness values, but this should do the trick (or something very close to this)
我尝试重现该问题,但发现边框确实按预期折叠:
您确定 ListBoxItem 是正在折叠的对象(而不是 ListBoxItem 中的 UI 对象)吗?
I tried to reproduce the issue, but found that the border does collapse as expected:
Are you certain the ListBoxItem is the object being collapsed (as opposed to the UI object in the ListBoxItem)?
这就是答案,但我不推荐,因为您无法撤消样式以恢复原始内容,而是您应该根据某些状态选择一些不同的数据绑定方法。
This is the answer but I wouldnt recommend because you cant undo the style to bring back what was original instead you should choose some different approach with databinding on the basis of certain states.