1

为了使列表框中的项目看起来不错

<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” 是为了防止
一些热名称太长,
但现在我想保持宽度=380
,但如果热名称太长而无法显示,它会显示“longhotname。 ..”
我该如何实现呢???

任何建议都会很好,谢谢!!!

4

1 回答 1

1

使用 TextTrimming 属性。

TextBlock text = new TextBlock();
text.TextTrimming = TextTrimming.WordEllipsis;
于 2013-03-26T08:37:35.783 回答