WPF 列表框的填充问题
在我的应用程序中,我为 ListBox
定义了一个 DataTemplate,它是一个带有拉伸边框的网格,并且内部有一个标签。 由于某种原因,我得到以下结果:
alt text http://dl. getdropbox.com/u/829214/q1.gif
正如您所看到的,ListBox
边框和项目边框之间有一个填充,并且当项目被选中。 我应该改变什么属性来解决这个问题?
编辑:
肯特的回答让我意识到,我的 DataTemplate 中的边框放置在项目容器(列表框项目)内,而不是像我想象的那样替换它。 最终,我将item容器样式中的padding设置为0,我的问题就解决了。
In my application, I defined a DataTemplate for a ListBox
to be a grid with a stretched border, and with a label inside it.
For some reason, I've got the following result:
alt text http://dl.getdropbox.com/u/829214/q1.gif
As you can see, there is a padding between the ListBox
border, and the item border, and this "padding" is marked when the item is selected.
What property should I change to solve it?
Edited:
Kent's answer made me realize, that the border in my DataTemplate is placed inside the item container (list box item), and not replacing it as I thought. Eventually, I set the padding in the item container style to be 0, and my problem was solved.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于代理问题,我看不到图像,但我认为您只需要设置容器的背景:
如果您希望选择突出显示在填充区域之外,只需设置
Background
返回到子容器中的null
。I can't see the image because of a proxy issue, but I think you just need to set the background of the container:
If you want the selection highlight to show outside the padded area, just set the
Background
back tonull
in the child container.