我正在制作一个聊天应用,其中我使用Datagrid显示聊天记录。现在我尝试同时选择多条消息,就像任何其他聊天应用程序一样。但我无法选择多个单元格。这是我的XAML代码。我尝试过使用不同的属性进行选择,但没有用。
<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=":-@" Icon="../Images/emoticons/14.png"/>
<local:EmoticonMapper Text=">:@" Icon="../Images/emoticons/14.png"/>
<local:EmoticonMapper Text=">:-@" 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>
答案 0 :(得分:0)
您需要在DataGrid中设置dio_get_fd()
。
设置SelectionMode以指定用户是否可以选择多个 行或一次只有一行。
$this->dio = dio_open($this->port, O_RDONLY | O_NOCTTY | O_NONBLOCK);
$this->fd = dio_get_fd($this->dio);
$this->e_read = new Event($this->base, $this->fd, Event::READ | Event::PERSIST,
[$this, '_onRead']);
$this->e_read->add();
$this->base->dispatch();