2010-07-21 67 views
0

顯而易見的MaxWidth會被忽略,即使此文本繼續超過父容器控件(位於silverlight區域的邊緣),「DisplayBox」TextBlock中的文本也會顯示整個文本。限制Silverlight中TextBlock的寬度

<win:HierarchicalDataTemplate x:Key="hierarchicalTemplate" ItemsSource="{Binding _children}"> 
    <Border BorderThickness="0" BorderBrush="Orange" HorizontalAlignment="Stretch" Background="{Binding Converter={StaticResource BackgroundConverter}}"> 
     <toolkit:DockPanel LastChildFill="True" Width="{Binding HeirarchyLevel, Converter={StaticResource WidthConverter}}" Height="20"> 
      <Canvas toolkit:DockPanel.Dock="Right" Width="20" MouseLeftButtonUp="Arrow_MouseLeftButtonDown"> 
       <Rectangle Width="20" Height="20" Fill="Transparent" /> 
       <Line Stroke="Black" X1="5" Y1="10" X2="17" Y2="10" /> 
       <Line Stroke="Black" X1="11" Y1="5" X2="17" Y2="10" /> 
       <Line Stroke="Black" X1="11" Y1="15" X2="17" Y2="10" /> 
      </Canvas> 
      <Ellipse Canvas.Top="5" Width="10" Height="10" Fill="Green" toolkit:DockPanel.Dock="Right" MouseLeftButtonDown="Ellipse_MouseLeftButtonDown" /> 
      <Canvas Width="Auto" Loaded="TextArea_Loaded"> 
       <TextBlock Name="DisplayBox" FontFamily="Arial" FontSize="17" Foreground="Black" Width="Auto" Text="{Binding TaskName}" MouseLeftButtonUp="TextBlock_MouseLeftButtonUp" /> 
       <TextBox Name="EditBox" FontFamily="Arial" FontSize="10" Foreground="Black" Height="20" Text="{Binding TaskName}" Visibility="Collapsed" LostFocus="TextBox_LostFocus" /> 
       <Line Stroke="Black" X1="0" Y1="10" X2="202" Y2="10" Width="Auto" /> 
      </Canvas> 
     </toolkit:DockPanel> 
    </Border> 
</win:HierarchicalDataTemplate> 

回答

1

你可以切換到使用一個網格,而不是一個帆布?一個TextBlock會當它是一個網格的孩子進行適當剪裁。這不是畫布的真實。

+0

豔麗。成功了! – Druzil 2010-07-22 10:20:50

1
 <Canvas Width="Auto" Loaded="TextArea_Loaded"> 
**<Border>**      
<TextBlock Name="DisplayBox" FontFamily="Arial" FontSize="17" Foreground="Black" Width="Auto" Text="{Binding TaskName}" MouseLeftButtonUp="TextBlock_MouseLeftButtonUp" /> 
        <TextBox Name="EditBox" FontFamily="Arial" FontSize="10" Foreground="Black" Height="20" Text="{Binding TaskName}" Visibility="Collapsed" LostFocus="TextBox_LostFocus" /> 
        <Line Stroke="Black" X1="0" Y1="10" X2="202" Y2="10" Width="Auto" /> 
**</Border>** 
       </Canvas> 

也應該工作。 (邊框將會標籤的最大長度,而邊框本身將不可見其厚度爲0.