OnmouseOver 在超链接上显示 mvvm mvvm light wpf 中的图像

发布于 2024-09-15 08:31:08 字数 125 浏览 3 评论 0原文

我想在 wpf xaml 中使用超链接。每当鼠标移到超链接上时,它都应该显示与该超链接相关的图像,当鼠标离开时,图像应该消失。如何使用绑定来解决这个问题。我正在使用 mvvm light。

请建议。

谢谢

I want to use hyperlink in wpf xaml. Whenever mouse comes over the hyperlink, it should show image related to that hyperlink and when mouse gets away the image should disappear. How to go about this using bindings. I am using mvvm light.

Kindly Suggest.

Thanks

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

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

发布评论

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

评论(1

百善笑为先 2024-09-22 08:31:08

如果您想以 MVVM 风格完成此任务,您需要的基本框架是...

您需要首先设置一个行为来命令超链接 MouseEnter MouseLeave 事件。

<Hyperlink NavigateUri="Uri">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="MouseEnter">
            <Command:EventToCommand Command="HoverCommand" PassEventArgs="True" />
        </i:EventTrigger>
    <i:Interaction.Triggers>
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="MouseLeave">
            <Command:EventToCommand Command="HoverCommand" PassEventArgs="True" />
        </i:EventTrigger>
    <i:Interaction.Triggers>
    Link text.
</Hyperlink>

现在设置一个当其 DataContext 不为 null 时将悬停的控件

使用该命令将悬停时的控件 DataContext 设置为图像的 Uri,在离开时将 datacontext 设置为 null。

The basic framework of what you will need, if you want to accomplish this in an MVVM style is...

You will need to start by setting up a Behavior to Command the Hyperlinks MouseEnter MouseLeave events.

<Hyperlink NavigateUri="Uri">
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="MouseEnter">
            <Command:EventToCommand Command="HoverCommand" PassEventArgs="True" />
        </i:EventTrigger>
    <i:Interaction.Triggers>
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="MouseLeave">
            <Command:EventToCommand Command="HoverCommand" PassEventArgs="True" />
        </i:EventTrigger>
    <i:Interaction.Triggers>
    Link text.
</Hyperlink>

Now setup a control that will hover when the its DataContext is not null

Use the command to set the controls DataContext on hover to the Uri of the image, on Leave set the datacontext to null.

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