2016-05-19 3 views
0

DataGridを使用するアプリケーションを構築しています。 1つの列は、ユーザーがコメントを入力することを許可し、別の列は、項目の説明を含みます。問題は、コメントセクションに大部分の行を構成したいが、説明列が多くの水平スペースを占めていることです。十分な垂直方向の部屋がありますが、1行にしか表示されません。それを強制的に複数の行に分割する方法はありますか?幅を制限するだけでデータがカットされます。C#/ WPF動的に生成されるデータグリッドの改行を許可する

私のXAML

<Window x:Class="hotels.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     Title="MainWindow" Height="700" Width="1000" Loaded="Window_Loaded" WindowStyle="ThreeDBorderWindow"> 
    <Window.Resources> 
     <Style x:Key="Grouping" TargetType="{x:Type GroupItem}"> 
      <Setter Property="Template"> 
       <Setter.Value> 
        <ControlTemplate TargetType="{x:Type GroupItem}"> 
         <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center"> 
          <TextBlock Margin="10px" Foreground="White" Text="{Binding Name}" FontFamily="Arial Black" FontSize="18" Background="Blue"> 
          </TextBlock> 
          <ItemsPresenter> 


          </ItemsPresenter> 

         </StackPanel> 
        </ControlTemplate> 
       </Setter.Value> 
      </Setter> 
     </Style> 
    </Window.Resources> 
    <ScrollViewer> 
    <StackPanel Orientation="Vertical" Margin="20"> 

     <WrapPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="10, 0, 30, 0" VerticalAlignment="Center" > 
      <Label Content="Room:" HorizontalAlignment="Left" Margin="0,0,0,0" VerticalAlignment="Center" /> 
      <TextBox x:Name="roomTextBox" Margin="5,0,0,0" TextWrapping="Wrap" Width="50" Panel.ZIndex="-1" VerticalAlignment="Center"/> 
      <Label x:Name="locationLabel" Content="Location:" Margin="25,0,0,0" VerticalAlignment="Center" HorizontalAlignment="Right"/> 
      <ComboBox x:Name="locationComboBox" SelectionChanged="filterEmployees" ItemsSource="{Binding}" Margin="5,0,0,0" SelectedIndex="-1" VerticalAlignment="Center" Width="150"/> 




      <Label x:Name="inspectLabel" Content="Inspector:" HorizontalAlignment="Left" Margin="50,0,0,0" VerticalAlignment="Center" Height="27"/> 
      <ComboBox x:Name="inspectorBox" ItemsSource="{Binding}" HorizontalAlignment="Left" Margin="15,0,0,0" VerticalAlignment="Center" Width="100"/> 
      <Label x:Name="empLabel" Content="Attendant:" HorizontalAlignment="Left" Margin="50,0,0,0" VerticalAlignment="Center"/> 
     <ComboBox x:Name="employeeBox" ItemsSource="{Binding}" HorizontalAlignment="Left" Margin="5,0,0,0" VerticalAlignment="Center" Width="100"/> 



     </WrapPanel> 
      <WrapPanel VerticalAlignment="Center" HorizontalAlignment="Center" Margin="50, 0, 50, 0"> 
       <Label x:Name="scoreLabel" Content="Score: " FontFamily="Arial Black" FontSize="24" HorizontalAlignment="Center" VerticalAlignment="Center"></Label> 
       <Label x:Name="currentPointLabel" FontSize="24" Foreground="IndianRed" FontFamily="Arial Black" HorizontalAlignment="Center" VerticalAlignment="Center"></Label> 
       <Label FontSize="24" Foreground="ForestGreen" FontFamily="Arial Black" x:Name="totalPointLabel" HorizontalAlignment="Center" VerticalAlignment="Center"></Label> 
      </WrapPanel> 

      <DataGrid CanUserAddRows="False" CanUserDeleteRows="False" x:Name="itemGrid" Width="Auto" AutoGenerateColumns="False" ItemsSource="{Binding}" Margin="0,0,0,0" MinHeight="400" AlternatingRowBackground="LightSteelBlue" RowBackground="SteelBlue" CanUserResizeRows="False" CanUserSortColumns="False" CanUserReorderColumns="False" CanUserResizeColumns="False" FontFamily="Arial Black" VerticalContentAlignment="Center" VerticalAlignment="Center" > 
       <DataGrid.GroupStyle> 
        <GroupStyle ContainerStyle="{StaticResource Grouping}"> 
         <GroupStyle.Panel> 
          <ItemsPanelTemplate> 
           <DataGridRowsPresenter></DataGridRowsPresenter> 
          </ItemsPanelTemplate> 
         </GroupStyle.Panel> 
        </GroupStyle> 
       </DataGrid.GroupStyle> 

      <DataGrid.Columns> 

        <DataGridTextColumn IsReadOnly="True" Width="auto" Header="Description" Binding="{Binding Description}" CanUserResize="False" /> 
       <DataGridTextColumn IsReadOnly="True" Width="auto" Header="Points Possible" Binding="{Binding Points}" /> 

       <DataGridTemplateColumn Header="Deductions" > 
        <DataGridTemplateColumn.CellTemplate> 
         <DataTemplate> 
           <ComboBox Height="40" VerticalAlignment="Center" HorizontalAlignment="Center" Width="Auto" ItemsSource="{Binding Score}" SelectedIndex="0" SelectionChanged="updateScore" /> 
         </DataTemplate> 
        </DataGridTemplateColumn.CellTemplate> 
         <DataGridTemplateColumn.CellEditingTemplate> 
          <DataTemplate> 
           <ComboBox ItemsSource="{Binding Score}" SelectedIndex="0" SelectionChanged="updateScore" Height="40" Width="Auto" /> 
          </DataTemplate> 
         </DataGridTemplateColumn.CellEditingTemplate> 
        </DataGridTemplateColumn> 
        <DataGridTextColumn IsReadOnly="True" Width="50" Header="Score" Binding="{Binding Current}" /> 
        <DataGridTemplateColumn Header="Comments" MinWidth="100" Width="*"> 
        <DataGridTemplateColumn.CellTemplate> 
         <DataTemplate> 

          <TextBox Text="{Binding Comments}" Margin="10" Width="Auto" Height="100" TextChanged="TextBox_TextChanged"></TextBox> 

          </DataTemplate> 
        </DataGridTemplateColumn.CellTemplate> 
         <DataGridTemplateColumn.CellEditingTemplate> 
          <DataTemplate> 
           <TextBox Text="{Binding Comments, Mode=TwoWay}" Margin="10" Width="Auto" Height="100"></TextBox> 
          </DataTemplate> 
         </DataGridTemplateColumn.CellEditingTemplate> 
        </DataGridTemplateColumn> 


      </DataGrid.Columns> 

     </DataGrid> 

      <Button x:Name="submitButton" Click="submitData" Content="Submit" HorizontalAlignment="right" Margin="00, 0, 00, 00 " VerticalAlignment="Center" Width="75"/> 



    </StackPanel> 
    </ScrollViewer> 
</Window> 

とスクリーンショットので、おそらくy'allのは、私が

enter image description here

感謝を意味しています何の良いアイデアを得ることができます!

答えて

1

あなたのDataGridTextColumnにElementStyleを追加し、TextWrappingプロパティを設定するためにそれを使用する必要があります。

<DataGridTextColumn IsReadOnly="True" Width="auto" Header="Description" Binding="{Binding Description}" CanUserResize="False" /> 
     <DataGridTextColumn.ElementStyle> 
      <Style>        
       <Setter Property="TextBlock.TextWrapping" Value="Wrap" /> 
      </Style> 
     </DataGridTextColumn.ElementStyle> 
<DataGridTextColumn/> 
0

コメントテキストボックスにTextWrapping = "Wrap"を追加する必要があります。

+0

おかげで、それは私がラップする必要がコメント欄ではありません - それは、説明欄のテキストです。申し訳ありませんが、私は少し不明な場合。 – KellyMarchewa

関連する問題