wpf 设置ListView的行间距

Jerss 2012-03-01 10:11:39
直接贴上xml代码,绑定的Resources里面我设置了 Height属性,可为什么只是把这一行中的数据或者是子控件的高度改变了,为什么没有改变整行的高??????

<evo:EvoChildWin.Resources>
<DataTemplate x:Key="DataTemplate1">
<Grid Height="25">
<ComboBox ItemsSource="{Binding Attributevalues}" IsEditable="True" DisplayMemberPath="Value" Name="cbAttribute" Text="{Binding Path=Value, Mode=TwoWay}" Width="140" />
</Grid>
</DataTemplate>

<DataTemplate x:Key="DataTemplate2">
<Grid Height="25">
<Label Content="{Binding Path=Attributename}" Width="140" />
</Grid>
</DataTemplate>
</evo:EvoChildWin.Resources>


<ListView BorderBrush="SandyBrown" ItemTemplate="{DynamicResource DataTemplate1}" BorderThickness="1" Height="271" HorizontalAlignment="Left" Margin="670,44,0,0" Name="lstAttributes" SelectionMode="Multiple" TabIndex="25" VerticalAlignment="Top" Width="332" >
<ListView.View>
<GridView x:Name="cbAttribute">
<GridViewColumn Header="属性名称" Width="140" CellTemplate="{DynamicResource DataTemplate2}" />
<GridViewColumn Header="属性值" Width="160" CellTemplate="{DynamicResource DataTemplate1}">
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
...全文
1796 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Jerss 2012-03-01
  • 打赏
  • 举报
回复
二楼正解,刚才自己摸索出来了,不过还是谢谢 !

改Padding的value值就ok啦,就直接将 GridViewColumn 中的子控件 与GridViewColumn的上下间距缩小
<Setter Property="Padding" Value="0"/>


结账

沝林 2012-03-01
  • 打赏
  • 举报
回复
如果是系统默认样式的话,可以给ListViewItem样式追加margin属性来设置行距:


<Style x:Key="listviewItemKey" TargetType="{x:Type ListViewItem}">
<Setter Property="Margin" Value="4"/>
<!--Setter Property="Padding" Value="4"/-->
</Style>


<ListView ItemContainerStyle="{StaticResource listviewItemKey}"../>


如果你已经定义过ListViewItem样式,那么可能需要在上述样式中加上BaseOn属性,如果不行就需要修改你的ListViewItem样式
EnForGrass 2012-03-01
  • 打赏
  • 举报
回复
自己写style

111,098

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧