我有一个ListBox,显示一个ObalentableCollection的Talent对象.当用户将鼠标悬停在ListBox中的每个项目上时,我想在ToolTip中显示有关Talent的几条信息.
我的ListBox:
<ListBox ItemsSource="{Binding ElementName=CE_Races_racesLB, Path=SelectedItem.Talents}" ItemTemplate="{StaticResource removableTalentListTemplate}" />
Run Code Online (Sandbox Code Playgroud)
ItemTemplate:
<DataTemplate x:Key="removableTalentListTemplate">
<StackPanel>
<TextBlock FontSize="13" Text="{Binding Path=tName}" VerticalAlignment="Center" Width="175" Height="18" Grid.Column="0" />
</StackPanel>
</DataTemplate>
Run Code Online (Sandbox Code Playgroud)
如果我将TextTipService.ToolTip ="{Binding Path = Description"添加到TextBlock属性,我可以显示Talent的描述.但是,当我尝试创建这样的自定义工具提示时:
<DataTemplate x:Key="removableTalentListTemplate">
<StackPanel>
<TextBlock FontSize="13" Text="{Binding Path=tName}" VerticalAlignment="Center" Width="175" Height="18" Grid.Column="0" />
<TextBlock.ToolTip>
<ToolTip>
<StackPanel>
<TextBlock Text="{Binding Path=Description}" />
</StackPanel>
</ToolTip>
</TextBlock.ToolTip>
</TextBlock>
</StackPanel>
</DataTemplate>
Run Code Online (Sandbox Code Playgroud)
当我转到鼠标悬停ListBox项时,工具提示只是说"System.Windows.Controls.StackPanel".我真的想创建一个很好的工具提示,显示很多信息,但我无法通过这个障碍.这是现在的截图:http://silkforge.com/dev/ss.jpg.您无法看到鼠标,但您可以在ListBox项目"Acute Hearing I"下看到工具提示.
以下是如何在选择单元格时设置背景的示例,但是当我实际单击单元格内部进行编辑时,颜色会发生变化.在编辑单元格时是否有触发器属性?我希望背景不要改变.
<DataGrid Name="DG1" ItemsSource="{Binding}" SelectionUnit="Cell" >
<DataGrid.CellStyle>
<Style TargetType="DataGridCell" >
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="SeaGreen"/>
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.CellStyle>
</DataGrid>
Run Code Online (Sandbox Code Playgroud)
回答我自己的问题,它看起来像Cell背景颜色是基于SystemColors.WindowBrushKey.覆盖这样的资源<SolidColorBrush x:Key="{x:Static SystemColors.WindowBrushKey}" Color="Red" />就可以了.`