DataGridComboBoxColumn ToolTip WPF
У меня есть DataGrid, который связан с CollectionViewSource. CollectionViewSource связан с наблюдаемой коллекцией stabList.
В Grid у меня есть ComboBoxColumn, который связан со строковым свойством 'Code' из stabList. Источником свойства Code является список с именем pType. (Извините, соглашения об именах все еще относительно новы для C#)
У меня есть еще один список с именем pEType, который дает описания каждого элемента pType, который я хотел бы отобразить в качестве всплывающей подсказки при наведении мыши на каждый элемент в раскрывающемся списке. Я прочитал несколько ответов, начинающих использовать DataGRidTemplateColumn, но потом я не могу заставить данные отображаться правильно. Пожалуйста, вы можете помочь и, возможно, показать мне решение этой проблемы? Заранее спасибо.
<CollectionViewSource x:Key="stabsView" Source="{Binding}" CollectionViewType="ListCollectionView" />
В ресурсах у меня есть EditingElementStyle
<Style x:Key="StandardComboBox" TargetType="ComboBox">
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="SelectedValue" Value="{Binding Code}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ComboBox">
<Grid>
<ToggleButton Name="ToggleButton" Foreground="Black" Template="{StaticResource ComboBoxToggleButton}" Focusable="false" IsChecked="{Binding Path=IsDropDownOpen,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}" ClickMode="Press">
</ToggleButton>
<ContentPresenter Name="ContentSite" IsHitTestVisible="False" Content="{TemplateBinding SelectionBoxItem}" ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}" Margin="3,3,23,3" VerticalAlignment="Center" HorizontalAlignment="Left" />
<TextBox OverridesDefaultStyle="True" VerticalContentAlignment="Center" SelectionBrush="Gray" CaretBrush="Black" Margin="0,0,30,0" TextWrapping="NoWrap" x:Name="PART_EditableTextBox" FontFamily="Trebuchet MS" Foreground="Black" Style="{x:Null}" Template="{StaticResource ComboBoxTextBox}" HorizontalAlignment="Left" Focusable="True" VerticalAlignment="Center" FontSize="15" Visibility="Hidden" IsReadOnly="{TemplateBinding IsReadOnly}"/>
<Popup Name="Popup" Grid.ColumnSpan="2" Placement="Bottom" IsOpen="{TemplateBinding IsDropDownOpen}" AllowsTransparency="True" Focusable="False" PopupAnimation="Slide">
<Grid Name="DropDown" SnapsToDevicePixels="True" MaxWidth="{TemplateBinding ActualWidth}" MinWidth="{TemplateBinding ActualWidth}" MaxHeight="{TemplateBinding MaxDropDownHeight}">
<Border Grid.ColumnSpan="2" Grid.RowSpan="2" x:Name="DropDownBorder" SnapsToDevicePixels="True" Background="Transparent" MaxWidth="{TemplateBinding ActualWidth}" BorderThickness="1" BorderBrush="Black"/>
<ScrollViewer Grid.ColumnSpan="2" ScrollViewer.CanContentScroll="False" Grid.Row="1" SnapsToDevicePixels="True">
<StackPanel IsItemsHost="True" Background="#FF252526">
</StackPanel>
</ScrollViewer>
</Grid>
</Popup>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsEditable" Value="true">
<Setter Property="IsTabStop" Value="false"/>
<Setter TargetName="PART_EditableTextBox" Property="Background" Value="#FF007ACC"/>
<Setter TargetName="PART_EditableTextBox" Property="Visibility" Value="Visible"/>
<Setter TargetName="PART_EditableTextBox" Property="Foreground" Value="Black"/>
<Setter TargetName="ContentSite" Property="Visibility" Value="Hidden"/>
</Trigger>
<Trigger Property="HasItems" Value="false">
<Setter TargetName="DropDownBorder" Property="MinHeight" Value="95"/>
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="IsTabStop" Value="false"/>
<Setter TargetName="PART_EditableTextBox" Property="Visibility" Value="Visible"/>
<Setter TargetName="PART_EditableTextBox" Property="Foreground" Value="White"/>
<Setter TargetName="PART_EditableTextBox" Property="IsEnabled" Value="False"/>
<Setter TargetName="PART_EditableTextBox" Property="Background" Value="White"/>
<Setter TargetName="ContentSite" Property="Visibility" Value="Hidden"/>
</Trigger>
<Trigger Property="IsGrouping" Value="true">
<Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
</Trigger>
<Trigger SourceName="Popup" Property="Popup.AllowsTransparency" Value="true">
<Setter TargetName="DropDownBorder" Property="Margin" Value="0,2,0,0"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
</Style.Triggers>
</Style>
DataGridComboBoxColumn
<DataGridComboBoxColumn Header="Code" Width="*" x:Name="Code" SelectedValueBinding="{Binding Code}" EditingElementStyle="{StaticResource StandardComboBox}">
<DataGridComboBoxColumn.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="Foreground" Value="White"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Background" Value="Transparent"/>
</Style>
</DataGridComboBoxColumn.CellStyle>
</DataGridComboBoxColumn>
из DataGrid
<DataGrid Padding="10" CanUserAddRows="False"
ItemsSource="{Binding Source={StaticResource stabsView}}" AutoGenerateColumns="False" x:Name="dgStabs" SelectionUnit="FullRow"
CanUserReorderColumns="False" CanUserResizeColumns="False" CanUserResizeRows="False"
CurrentCellChanged="dgStabs_CurrentCellChanged" Grid.ColumnSpan="2" RowHeaderWidth="5"
PreviewMouseLeftButtonDown="DataGridCell_PreviewMouseLeftButtonDown" KeyUp="dgStabs_KeyUp" PreviewTextInput="DataGridCell_PreviewTextInput" GotFocus="dgStabs_GotFocus" >
<DataGrid.Columns>
<DataGridTextColumn CellStyle="{StaticResource DataGridTextColumn}" Binding="{Binding EntryNo}" Header="No" IsReadOnly="True" Width="*"/>
<DataGridTextColumn CellStyle="{StaticResource DataGridTextColumn}" Binding="{Binding RecEntry}" Header="Rec.Entry" IsReadOnly="True" Width="*"/>
<DataGridComboBoxColumn Header="Code" Width="*" x:Name="Code" SelectedValueBinding="{Binding Code}" EditingElementStyle="{StaticResource StandardComboBox}">
<DataGridComboBoxColumn.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="Foreground" Value="White"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Background" Value="Transparent"/>
</Style>
</DataGridComboBoxColumn.CellStyle>
</DataGridComboBoxColumn>
<DataGridCheckBoxColumn Binding="{Binding Prox, UpdateSourceTrigger=PropertyChanged}" Header="Prox" x:Name="Prox" Width="*"/>
<DataGridTextColumn CellStyle="{StaticResource DataGridTextColumn}" Binding="{Binding Position}" Header="Position" Width="*"/>
<DataGridTextColumn CellStyle="{StaticResource DataGridTextColumn}" Binding="{Binding Tip}" Header="Tip (mV)" Width="*"/>
<DataGridTextColumn CellStyle="{StaticResource DataGridTextColumn}" Binding="{Binding LineNo}" Header="Line No" Width="*"/>
<DataGridTextColumn CellStyle="{StaticResource DataGridTextColumn}" Binding="{Binding Exp}" Header="Exposure (%)" Width="*"/>
<DataGridTextColumn CellStyle="{StaticResource DataGridTextColumn}" Binding="{Binding Remote}" Header="Remote (mV)" Width="*"/>
<DataGridTextColumn CellStyle="{StaticResource DataGridTextColumn}" Binding="{Binding Field}" Header="Field (mV)" Width="*"/>
<DataGridTextColumn CellStyle="{StaticResource DataGridTextColumn}" Binding="{Binding LongTime}" Header="Time" Width="*" />
</DataGrid.Columns>
<DataGrid.ContextMenu>
<ContextMenu>
<MenuItem Header="Copy" x:Name="cmCopy" Click="cmCopy_Click" />
<MenuItem Header="Paste" x:Name="cmPaste" Click="cmPaste_Click" />
</ContextMenu>
</DataGrid.ContextMenu>
<DataGrid.Resources>
<Style TargetType="DataGridRow">
<Style.Triggers>
<DataTrigger Binding="{Binding Code}" Value="NV">
<Setter Property="Background" Value="#FF8E8A8A"/>
</DataTrigger>
<DataTrigger Binding="{Binding Code}" Value="CS">
<Setter Property="Background" Value="Green"/>
</DataTrigger>
<DataTrigger Binding="{Binding Code}" Value="CR">
<Setter Property="Background" Value="Green"/>
</DataTrigger>
</Style.Triggers>
</Style>
</DataGrid.Resources>
</DataGrid>
В коде у меня есть
Code.ItemsSource = MainWindow.pType;
CollectionViewSource itemCollectionViewSource;
itemCollectionViewSource = (CollectionViewSource)(FindResource("stabsView"));
itemCollectionViewSource.Source = stabList;