出于我想使列表框中的项目看起来不错的目的
<ListBox
Height="Auto"
HorizontalAlignment="Left"
Margin="0,0,0,0"
Name="hotSpotListBox"
VerticalAlignment="Top"
Width="460"
ItemsSource="{Binding}"
ScrollViewer.VerticalScrollBarVisibility="Disabled"
SelectionChanged="hotSpotListBoxSelectionChanged" >
<ListBox.ItemTemplate>
<DataTemplate>
StackPanel Margin="10,0,12,4
Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<TextBlock
Width="380"
Margin="0,4,12,4"
FontSize="24"
Text="{Binding hotname}"
Foreground="#FF407CED"
TextWrapping="Wrap"
Tap="QueryHotSpotItem_Tap"/>
<Image
Margin="0,0,0,0"
Source="/Images/ico_name.png"
Tap="HotSpotIcon_Tap"/>
</StackPanel>
<TextBlock
Margin="0,0,12,4"
FontSize="22"
Text="{Binding address}"
Foreground="Black"
TextWrapping="Wrap"
Tap="QueryHotSpotItem_Tap"/>
<TextBlock
Margin="0,4,12,4"
FontSize="24"
Text="{Binding city}"
Height="1"
Width="1"
Visibility="Collapsed"/>
<TextBlock
Margin="0,0,12,4"
FontSize="22"
Text="{Binding hottype}"
Height="1"
Width="1"
Visibility="Collapsed" />
<TextBlock
Margin="0,0,12,4"
FontSize="2"
Text="{Binding coverarea}"
Height="1"
Width="1"
Visibility="Collapsed" />
<TextBlock
Margin="0,0,12,4"
FontSize="2"
Text="{Binding longitude}"
Height="1"
Width="1"
Visibility="Collapsed" />
<TextBlock
Margin="0,0,12,4"
FontSize="2"
Text="{Binding latitude}"
Height="1"
Width="1"
Visibility="Collapsed" />
</StackPanel>
</DataTemplate>
/ListBox.ItemTemplate>
</ListBox>
请查看代码中的注释:
伟大的程序员!!!小心!!
这里,width = 380是一个很好的布局,textwrapping =“wrap”是为了防止
一些hotname太长了
但现在我想保持宽度= 380
但如果hotname太长而无法显示,则显示“longhotname ...”
我怎么能实现这个???
任何建议都会很好,谢谢!
答案 0 :(得分:1)
使用TextTrimming属性。
TextBlock text = new TextBlock();
text.TextTrimming = TextTrimming.WordEllipsis;