当鼠标悬停在某些单元格上时 DataGrid 弹出框

发布于 2024-12-22 06:25:12 字数 750 浏览 2 评论 0原文

我有一个数据网格,其中有 5 列,名称如下

RowID, 姓名, 年龄, 高度, 图像

我想要做的是,当鼠标悬停在图像列中的单元格上时,如果那里有图像,我希望出现一个弹出框。我知道我可以只使用弹出窗口的工具提示,但检查的最佳方法是将鼠标悬停在单元格上,以及单元格是否存在图像,如果有,则显示弹出窗口。

编辑:- 添加了图像列的 DataGrid 列的代码

<DataGridTemplateColumn Header="Image">                        
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <Image Width="32" Height="32" HorizontalAlignment="Center" VerticalAlignment="Center"
                Source="{Binding IMG, Converter={StaticResource ImageConvert}}"/>                                           
        </DataTemplate>                            
    </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn> 

I have a Datagrid with say 5 Columns named as follows

RowID,
Name,
Age,
Height,
Image

What I want to do is when the mouse is over a cell in the Image Column, if there is an image there I want a pop up box to appear. I know I can just use a tool tip for the pop up but what's the best way of doing the check of is mouse over cell and does cell have an image present, if so then display popup.

EDIT:- Added code for DataGrid Column for Image Column

<DataGridTemplateColumn Header="Image">                        
    <DataGridTemplateColumn.CellTemplate>
        <DataTemplate>
            <Image Width="32" Height="32" HorizontalAlignment="Center" VerticalAlignment="Center"
                Source="{Binding IMG, Converter={StaticResource ImageConvert}}"/>                                           
        </DataTemplate>                            
    </DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn> 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

美羊羊 2024-12-29 06:25:12

您可以使用 IsMouseOver 属性来确定鼠标是否位于对象上方,并使用 MultiDataTrigger 来评估多个条件。

<Style TargetType="Image">
    <Style.Triggers>
        <MultiDataTrigger>
            <MultiDataTrigger.Conditions>
                <Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" Value="True" />
                <Condition Binding="{Binding IMG, Converter={StaticResource IsImageNullConverter}}" Value="False" />
            </MultiDataTrigger.Conditions>

            <Setter Property="ToolTip">
                <Setter.Value>
                    <!-- Your ToolTip here -->
                </Setter.Value>
            </Setter>
        </MultiDataTrigger>
    </Style.Triggers>
</Style>

You can use the IsMouseOver property to determine if the mouse is over an object, and a MultiDataTrigger to evaluate multiple conditions.

<Style TargetType="Image">
    <Style.Triggers>
        <MultiDataTrigger>
            <MultiDataTrigger.Conditions>
                <Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}" Value="True" />
                <Condition Binding="{Binding IMG, Converter={StaticResource IsImageNullConverter}}" Value="False" />
            </MultiDataTrigger.Conditions>

            <Setter Property="ToolTip">
                <Setter.Value>
                    <!-- Your ToolTip here -->
                </Setter.Value>
            </Setter>
        </MultiDataTrigger>
    </Style.Triggers>
</Style>
想你只要分分秒秒 2024-12-29 06:25:12

有几种方法。我建议创建一个模板列类型/样式,并在鼠标位于单元格内时将其实现为触发器。

There are a couple of ways. What I would recommend is to create a Template column type / style and implement this as a trigger when the mouse is within the cell.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文