积极答复者
如何设置每个item的间距?

问题
答案
-
你好 yooho,
我现在明白你第二个问题的意思了。
你可以用Style去设置ListBoxItem的Margin属性,这样就能满足你的需求了,在你的项目中加入下面的代码:
<Window.Resources>
<Style TargetType="ListBoxItem">
<Setter Property="Margin" Value="20"/>
</Style>
</Window.Resources>
至于Margin的值你可以随便设置,你也可以这样设置:Value="0,0,0,20",四个数字分别代表举例四个边界的距离。
Best regards,
Sheldon _Xiao [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 yooho 2011年1月29日 1:11
全部回复
-
你好 yooho,
对于你的第一个问题,我觉得你可以在你的ListBoxItem中加入TextBlock,然后设置这个TextBlock的TextAlignment属性去控制文本的显示,比如你可以这样实现(我根据你上一个问题写的):
<ListBox.ItemTemplate>
<DataTemplate>
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="40" ></RowDefinition>
<RowDefinition Height="30" ></RowDefinition>
</Grid.RowDefinitions>
<Image Source="{Binding Pic}"/>
<TextBlock TextAlignment="Center" Text="{Binding Name}" Grid.Row="1"/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
这样你的文字就会居中显示了。
对于你的第二个问题,我不清楚你这个Item的间距是什么意思,根据我个人的理解,你可以设置DataTemplate中的Grid的Margin属性去完成,比如我上面的参考代码中写的那样 Margin = “10”.
如果有什么地方不明白的,告诉我。
Best regards,
Sheldon _Xiao [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已建议为答案 Sheldon _XiaoModerator 2011年2月12日 8:18
-
-
你好 yooho,
我现在明白你第二个问题的意思了。
你可以用Style去设置ListBoxItem的Margin属性,这样就能满足你的需求了,在你的项目中加入下面的代码:
<Window.Resources>
<Style TargetType="ListBoxItem">
<Setter Property="Margin" Value="20"/>
</Style>
</Window.Resources>
至于Margin的值你可以随便设置,你也可以这样设置:Value="0,0,0,20",四个数字分别代表举例四个边界的距离。
Best regards,
Sheldon _Xiao [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 yooho 2011年1月29日 1:11