2012-06-13 73 views
2

有人可以告訴我爲什麼Wrapping不能處理這些文本塊嗎? 我只是不知道爲什麼,我改變了我的一切stackpanels到網格,以避免無限空間的問題,但它仍然沒有工作...Textblock textwrapping無法正常工作

<Border x:Name="SummaryRightSideContainerBorder" Grid.Column="1" 
     Margin="10,10,10,10" BorderBrush="Black" 
     BorderThickness="1"> 
    <ContentControl x:Name="SummaryRightSideContainerContentControl" Content="{Binding SelectedItem, ElementName=SummaryTreeView}"> 
     <ContentControl.Resources> 
      <DataTemplate DataType="{x:Type ViewModelsProject:ProjectViewModel}"> 
       <StackPanel> 
        <TextBlock Text="Displaying Project DataContract stuff..." /> 
       </StackPanel> 
      </DataTemplate> 
      <DataTemplate DataType="{x:Type ViewModelsProject:SequenceViewModel}"> 
       <StackPanel> 
        <TextBlock Text="Displaying Sequence DataContract stuff..." /> 
       </StackPanel> 
      </DataTemplate> 
      <DataTemplate DataType="{x:Type ViewModelsProject:GroupViewModel}"> 
       <StackPanel> 


        <DataGrid Margin="10" AutoGenerateColumns="False" 
            Background="Transparent" BorderThickness="0" 
            CanUserAddRows="False" 
            CellStyle="{DynamicResource dgCellStyle}" 
            ColumnHeaderStyle="{DynamicResource dgHeader}" 
            DataContext="{Binding ElementName=SummaryTreeView, 
                 Path=SelectedItem}" 
            GridLinesVisibility="None" 
            ItemsSource="{Binding Standards}" 
            Padding="0" RowHeaderWidth="0" ScrollViewer.HorizontalScrollBarVisibility="Disabled"> 
         <DataGrid.Resources> 
          <Style x:Key="dgHeader" TargetType="{x:Type DataGridColumnHeader}"> 
           <Setter Property="Template"> 
            <Setter.Value> 
             <ControlTemplate TargetType="{x:Type DataGridColumnHeader}"> 
              <TextBlock Width="{TemplateBinding Width}" 
                  Padding="5" 
                  Text="{TemplateBinding Content}" 
                  TextAlignment="Left"> 
                <TextBlock.Background> 
                 <LinearGradientBrush StartPoint="0,0" EndPoint="0,1"> 
                  <GradientStop Offset="0.0" Color="#373638" /> 
                  <GradientStop Offset="1.0" Color="#77797B" /> 
                 </LinearGradientBrush> 
                </TextBlock.Background> 
              </TextBlock> 
             </ControlTemplate> 
            </Setter.Value> 
           </Setter> 
           <Setter Property="OverridesDefaultStyle" Value="True" /> 
           <Setter Property="Background" Value="Green" /> 
           <Setter Property="Foreground" Value="White" /> 
           <Setter Property="FontSize" Value="12" /> 
           <Setter Property="Background"> 
            <Setter.Value> 
             <LinearGradientBrush StartPoint="0,0" EndPoint="0,1"> 
              <GradientStop Offset="0.0" Color="#373638" /> 
              <GradientStop Offset="1.0" Color="#77797B" /> 
             </LinearGradientBrush> 
            </Setter.Value> 
           </Setter> 
          </Style> 
          <Style x:Key="dgCellStyle" TargetType="{x:Type DataGridCell}"> 
           <Style.Triggers> 
            <Trigger Property="DataGridCell.IsSelected" Value="True"> 
             <Setter Property="Background" Value="White" /> 
             <Setter Property="Foreground" Value="Black" /> 
             <Setter Property="BorderThickness" Value="0" /> 
            </Trigger> 
           </Style.Triggers> 
          </Style> 
         </DataGrid.Resources> 
         <DataGrid.Columns> 
          <DataGridTemplateColumn Header="Standards"> 
           <DataGridTemplateColumn.CellTemplate> 
            <DataTemplate> 


             <Grid Margin="5"> 
              <Grid.RowDefinitions> 
               <RowDefinition /> 
               <RowDefinition /> 
              </Grid.RowDefinitions> 
              <TextBlock Grid.Row="0" Text="{Binding Path=StepMaster.Description}" VerticalAlignment="Center" FontWeight="SemiBold"/> 
              <Grid Grid.Row="1"> 
               <Grid.RowDefinitions> 
                <RowDefinition /> 
                <RowDefinition /> 
                <RowDefinition /> 
               </Grid.RowDefinitions> 
               <Grid.ColumnDefinitions> 
                <ColumnDefinition Width="Auto" /> 
                <ColumnDefinition Width="*" /> 
               </Grid.ColumnDefinitions> 
               <TextBlock Grid.Row="0" Grid.Column="0" Text="Standard: " VerticalAlignment="Top"/> 
               <TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding Path=Standard}" Margin="5,0,0,0" VerticalAlignment="Top" TextWrapping="Wrap"/> 

               <TextBlock Grid.Row="1" Grid.Column="0" Text="Details: " VerticalAlignment="Top"/> 
               <TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding Path=Details}" Margin="5,0,0,0" VerticalAlignment="Top" TextWrapping="Wrap"/> 

               <TextBlock Grid.Row="2" Grid.Column="0" Text="Comments: " VerticalAlignment="Top"/> 
               <TextBlock Grid.Row="2" Grid.Column="1" Text="{Binding Path=Comments}" Margin="5,0,0,0" VerticalAlignment="Top" TextWrapping="Wrap"/> 
              </Grid> 
             </Grid> 

            </DataTemplate> 
           </DataGridTemplateColumn.CellTemplate> 
          </DataGridTemplateColumn> 
         </DataGrid.Columns> 
        </DataGrid> 


       </StackPanel> 
      </DataTemplate> 
      <DataTemplate DataType="{x:Type ViewModelsProject:StepViewModel}"> 
       <UniformGrid Rows="3"> 
        <TextBlock Margin="10" FontWeight="DemiBold" 
           Text="Standards" /> 
        <TextBlock Margin="10" FontWeight="DemiBold" 
           Text="Standards Details" /> 
        <StackPanel Orientation="Vertical"> 
         <DataGrid Margin="10" AutoGenerateColumns="False" 
          <Another data grid is here /> 
         </DataGrid> 
        </StackPanel> 
       </UniformGrid> 
      </DataTemplate> 
     </ContentControl.Resources> 
    </ContentControl> 
</Border> 
+0

設置所有RowDefinition Height =「Auto」。嘗試一個硬寬度不是最終答案,而是看看會發生什麼。 – Paparazzi

+0

它現在使用進行包裝,但我不希望在該列上放置固定的寬度,因爲用戶可能想要展開窗口,並且看上去「有趣」... –

+0

我想它可能由''嘗試將* Width改變爲* *或特定值,如* Carlos H *所示。 –

回答

3

原來,使這項工作的唯一方法是直接在DataGrid中使用屬性:

MaxWidth="{Binding ElementName=SummaryRightSideContainerBorder, Path=ActualWidth}" ColumnWidth="*" 

MaxWidth用於使Datagrid本身不超過其容器邊界,並使用ColumnWidth以便列使用數據網格中可用空間的100%。

Blam的回答讓我找到了解決方案的正確途徑。

1

作爲一個答案,你需要設置第二列

<ColumnDefinition Width="*"/> 

所以它受到限制。 *表示容器的大小。現在,它正在成長的容器外(屏幕)

第一列汽車是OK

+0

我認爲這將工作,但它沒有,只要我將第二列寬度從「200」更改爲「*」它停止再次包裝...也許這是TemplateColumn干擾網格的正常行爲,但我我不確定。 –

+0

發佈您的當前xaml – Paparazzi

+0

我剛剛發佈了我的完整xaml,我該如何給一個人點數? –