【发布时间】:2016-06-28 20:34:22
【问题描述】:
当用户在 DataGrid 中悬停一行时,我想显示一个弹出窗口,其中包含有关该行的一些信息。 我坚持如何将 DataTrigger 绑定到动态填充的 DataGrid 表中的每一行。
我找到了仅针对工具提示的解决方案,但工具提示不适合我,因为我需要对弹出窗口进行更多控制(当用户将鼠标光标移动到另一个控件时不要立即隐藏它,能够单击弹出窗口用鼠标等)
这是我试图将弹出 DataTrigger 绑定到每个 DataGrid 行的 XAML 代码(我在下面的代码中放置了带有问题的 cmets)
<Window x:Class="VKPN.UI.Windows.TestWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:VKPN.UI.Windows"
mc:Ignorable="d"
Title="TestWindow" SizeToContent="WidthAndHeight">
<Grid>
<Popup Name="UserPopup" Placement="RelativePoint" HorizontalOffset="-5" VerticalOffset="0"
PlacementTarget="{Binding ElementName=ThisUserControl}">
<Popup.Style>
<Style TargetType="Popup">
<Style.Triggers>
<!--How to specify binding to every DataGridTable row below?-->
<DataTrigger Binding="{Binding ElementName=DataGridTable, Path=???}" Property="IsMouseOver" Value="True">
<Setter Property="IsOpen" Value="True"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Popup.Style>
<Label>
<Label.Style>
<Style TargetType="Label">
<Style.Triggers>
<!--How to specify binding to every DataGridTable row below?-->
<DataTrigger Binding="{Binding ElementName=???}" Property="IsMouseOver" Value="True">
<!--DataGrid row has a column "id" which I want to show in the label. Did I do it correct below?-->
<Setter Property="Content" Value="{Binding RelativeSource={RelativeSource Mode=Self}, Path=DataContext.id}"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Label.Style>
</Label>
</Popup>
<DataGrid Name="DataGridTable" ItemsSource="{Binding}" IsReadOnly="True" ScrollViewer.CanContentScroll="True" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.HorizontalScrollBarVisibility="Auto">
</DataGrid>
</Grid>
</Window>
请帮我弄清楚怎么做。
【问题讨论】:
-
你找到解决办法了吗?
标签: wpf xaml binding datagrid datatrigger