【发布时间】:2016-04-01 07:19:54
【问题描述】:
我有一个包含 ListBoxItems 的 ListBox,我已将按钮添加为垂直形式的 ListBoxItems。 按钮之间的间距由边距设置。 但是当我单击按钮下方时,它正在调用该事件。
我应该如何删除它?以及如何将 ListBoxItem & Margin 的高度设置为该项目?
【问题讨论】:
-
“点击按钮下方”是什么意思?你的意思是
Margin区域。另外,分享您尝试过的代码。
我有一个包含 ListBoxItems 的 ListBox,我已将按钮添加为垂直形式的 ListBoxItems。 按钮之间的间距由边距设置。 但是当我单击按钮下方时,它正在调用该事件。
我应该如何删除它?以及如何将 ListBoxItem & Margin 的高度设置为该项目?
【问题讨论】:
Margin 区域。另外,分享您尝试过的代码。
您可以使用ListBox.ItemContainerStyle 获取或设置渲染项目容器时使用的样式(ListBoxItems),Margin 将为您完成所需的任务:尝试以下代码:
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="Margin" Value="5"/>
<Setter Property="Height" Value="75"/> <!-- For setting height of control-->
<Setter Property="Width" Value="75"/> <!-- For setting widthof control-->
</Style>
</ListBox.ItemContainerStyle>
【讨论】:
<Style x:Key="ListBoxItemStyle" TargetType="ListBoxItem"> <Setter Property="Margin" Value="25"/> <Setter Property="Height" Value="75"/> <Setter Property="Width" Value="75"/> </ControlTemplate> </Setter.Value> </Setter> </Style>