2016-11-30 5 views
0

私はDatagridを使ってチャット履歴を表示しているチャットアプリケーションを作っています。他のチャットアプリと同じように、複数のメッセージを同時に選択しようとしています。しかし、私は1つ以上の細胞を選択することができません。ここに私のXAMLコードがあります。私は選択のために別のプロパティを使用しようとしましたが、使用しません。ここでwpf DataGridで複数の行や列を選択できませんWPF

<DataGrid x:Name="MainChatDataGrid" Margin="0,0,0,0" ItemsSource="{Binding Source={StaticResource UserMessagesCollection}}" 
          IsReadOnly="True" AutoGenerateColumns="False" CanUserAddRows="False" 
          HeadersVisibility="None" GridLinesVisibility="None" 
          BorderThickness="0" Background="White" 
          VerticalScrollBarVisibility="Auto" 
          HorizontalScrollBarVisibility="Disabled" 
          SelectionMode="Extended" 
          SelectionUnit="CellOrRowHeader" 
          SelectiveScrollingGrid.SelectiveScrollingOrientation="Both" 
          CopyingRowClipboardContent="dataGrid1_CopyingRowClipboardContent" 
          HorizontalAlignment="Stretch" VerticalAlignment="Stretch" 
          CanUserResizeRows="False" > 

        <DataGrid.GroupStyle> 
         <GroupStyle> 
          <GroupStyle.HeaderTemplate> 
           <DataTemplate> 
            <DockPanel Background="{x:Null}" > 
             <Rectangle HorizontalAlignment="Stretch" Fill="#FFCCCCCC" Height="3" 
                DockPanel.Dock="Top" Margin="7.5,10,80,15" /> 
             <TextBlock Text="{Binding Path=Name}" Foreground="Black" IsEnabled="True" 
                DockPanel.Dock="Right" HorizontalAlignment="Right" 
                FontFamily="Arial" Margin="0,-25,0,0"/> 
            </DockPanel> 
           </DataTemplate> 
          </GroupStyle.HeaderTemplate> 
         </GroupStyle> 
        </DataGrid.GroupStyle> 
        <DataGrid.RowStyle> 
         <Style TargetType="{x:Type DataGridRow}"> 
          <Style.Triggers> 
           <DataTrigger Binding="{Binding IsSenderLoggedInUser}" Value="True"> 
            <Setter Property="Background" Value="White" /> 
           </DataTrigger> 
           <DataTrigger Binding="{Binding IsSenderLoggedInUser}" Value="False"> 
            <Setter Property="Background" Value="White" /> 
           </DataTrigger> 
           <Trigger Property="IsSelected" Value="True" > 
            <Setter Property="Background" Value="White" /> 
           </Trigger> 
          </Style.Triggers> 
         </Style> 
        </DataGrid.RowStyle> 
        <DataGrid.Resources> 
         <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#FF666666"/> 
        </DataGrid.Resources> 
        <DataGrid.HorizontalGridLinesBrush> 
         <SolidColorBrush Color="LightGray" /> 
        </DataGrid.HorizontalGridLinesBrush> 
        <DataGrid.Columns > 
         <DataGridTemplateColumn Header="Image" > 
          <DataGridTemplateColumn.CellStyle> 
           <Style TargetType="DataGridCell"> 
            <Setter Property="Background" Value="{StaticResource columnBackgroundColor}"/> 
            <Setter Property="BorderBrush" Value="{StaticResource columnBorderColor}" /> 
            <Setter Property="BorderThickness" Value="0" /> 
           </Style> 
          </DataGridTemplateColumn.CellStyle> 
          <DataGridTemplateColumn.CellTemplate> 
           <DataTemplate> 

            <Image Source="{Binding SenderImageSource}" Width="40" Height="40" 
               VerticalAlignment="Top" Margin="0,2,0,0" Stretch="Fill" > 
             <Image.OpacityMask> 
              <VisualBrush Visual="{Binding ElementName=Mask}" /> 
             </Image.OpacityMask> 
            </Image> 
           </DataTemplate> 
          </DataGridTemplateColumn.CellTemplate> 
         </DataGridTemplateColumn> 
         <DataGridTemplateColumn> 
          <DataGridTemplateColumn.CellStyle> 
           <Style TargetType="DataGridCell"> 
            <Setter Property="Background" Value="{StaticResource columnBackgroundColor}" /> 
            <Setter Property="BorderBrush" Value="{StaticResource columnBorderColor}" /> 
            <Setter Property="BorderThickness" Value="0" /> 
           </Style> 
          </DataGridTemplateColumn.CellStyle> 
          <DataGridTemplateColumn.CellTemplate> 
           <DataTemplate> 
            <TextBox Margin="15,-1,0,0" Text="{Binding Sender}" 
             FontSize="12" VerticalAlignment="Top" 
              IsEnabled="True" 
              BorderThickness="0,0,0,0" 
             FontWeight="Bold" 
             Foreground="Black" 
             IsReadOnly="True" 
             HorizontalAlignment="Left" /> 
           </DataTemplate> 
          </DataGridTemplateColumn.CellTemplate> 
         </DataGridTemplateColumn> 
         <DataGridTemplateColumn Width="*"> 
          <DataGridTemplateColumn.CellStyle> 
           <Style TargetType="DataGridCell"> 
            <Setter Property="Background" Value="{StaticResource columnBackgroundColor}" /> 
            <Setter Property="BorderBrush" Value="{StaticResource columnBorderColor}" /> 
            <Setter Property="BorderThickness" Value="0" /> 
           </Style> 
          </DataGridTemplateColumn.CellStyle> 
          <DataGridTemplateColumn.CellTemplate> 
           <DataTemplate> 
            <local:RichTextBoxExt x:Name="rich" HorizontalAlignment="Left" SelectionBrush="Yellow" Margin="-55,15,0,0" IsReadOnly="True" BorderThickness="0,0,0,0" IsEnabled="True" IsUndoEnabled="False"> 
             <FlowDocument > 
              <Paragraph> 
               <Run Text="{Binding Message, Mode=OneWay}" /> 
              </Paragraph> 
             </FlowDocument> 
             <local:RichTextBoxExt.Emoticons> 
              <local:EmoticonMapper Text="^_^" Icon="../Images/emoticons/01.png"/> 
              <local:EmoticonMapper Text=":D" Icon="../Images/emoticons/02.png"/> 
              <local:EmoticonMapper Text=":-D" Icon="../Images/emoticons/02.png"/> 
              <local:EmoticonMapper Text=";)" Icon="../Images/emoticons/04.png"/> 
              <local:EmoticonMapper Text=";-)" Icon="../Images/emoticons/04.png"/> 
              <local:EmoticonMapper Text=":)" Icon="../Images/emoticons/05.png"/> 
              <local:EmoticonMapper Text=":-)" Icon="../Images/emoticons/05.png"/> 
              <local:EmoticonMapper Text="8)" Icon="../Images/emoticons/07.png"/> 
              <local:EmoticonMapper Text="8-)" Icon="../Images/emoticons/07.png"/> 
              <local:EmoticonMapper Text=":p" Icon="../Images/emoticons/08.png"/> 
              <local:EmoticonMapper Text=":-p" Icon="../Images/emoticons/08.png"/> 
              <local:EmoticonMapper Text=":o" Icon="../Images/emoticons/10.png"/> 
              <local:EmoticonMapper Text=":-o" Icon="../Images/emoticons/10.png"/> 
              <local:EmoticonMapper Text=":(" Icon="../Images/emoticons/12.png"/> 
              <local:EmoticonMapper Text=":-(" Icon="../Images/emoticons/12.png"/> 
              <local:EmoticonMapper Text=":'(" Icon="../Images/emoticons/13.png"/> 
              <local:EmoticonMapper Text=":'-(" Icon="../Images/emoticons/13.png"/> 
              <local:EmoticonMapper Text=":@" Icon="../Images/emoticons/14.png"/> 
              <local:EmoticonMapper Text=":[email protected]" Icon="../Images/emoticons/14.png"/> 
              <local:EmoticonMapper Text=">:@" Icon="../Images/emoticons/14.png"/> 
              <local:EmoticonMapper Text=">:[email protected]" Icon="../Images/emoticons/14.png"/> 
             </local:RichTextBoxExt.Emoticons> 
            </local:RichTextBoxExt> 
           </DataTemplate> 
          </DataGridTemplateColumn.CellTemplate> 
         </DataGridTemplateColumn> 
         <DataGridTemplateColumn> 
          <DataGridTemplateColumn.CellStyle> 
           <Style TargetType="DataGridCell"> 
            <Setter Property="Background" Value="{StaticResource columnBackgroundColor}"/> 
            <Setter Property="BorderBrush" Value="{StaticResource columnBorderColor}" /> 
            <Setter Property="BorderThickness" Value="0" /> 
           </Style> 
          </DataGridTemplateColumn.CellStyle> 
          <DataGridTemplateColumn.CellTemplate> 
           <DataTemplate> 
            <TextBox Text="{Binding FormattedTimeStamp,Mode= OneWay}" Foreground="Black" IsEnabled="True" IsReadOnly="True" BorderThickness="0,0,0,0" FontSize="10" Width="45" VerticalAlignment="Top" HorizontalAlignment="Left" 
             Margin="0,-1,0,0"/> 
           </DataTemplate> 
          </DataGridTemplateColumn.CellTemplate> 
         </DataGridTemplateColumn> 
        </DataGrid.Columns> 
       </DataGrid> 

は、あなたがあなたのDataGridにSelectionModeを設定する必要があり、選択したセル Chat App

答えて

0

の私のスクリーンショットです。

複数の 行を一度に選択できるかどうかを指定するためにSelectionModeを設定します。

DataGrid.SelectionMode

<DataGrid SelectionMode="Extended" 
+0

それが既に拡張だ@esiprogreammer。しかし、まだ動作していない –

+0

mmm、私は参照してください。あなたは 'SelectionUnit'を変更しようとしましたか? – esiprogrammer

+0

はいすべてのオプションを試しました。 –

関連する問題