WPF 通过数据绑定在图像上创建矩形标签

发布于 2024-09-05 20:41:34 字数 733 浏览 1 评论 0原文

我正在尝试向 WPF 图像添加图像标签,但运气不佳。如果可能的话,我想通过数据绑定来完成。我可以使用 DataTemplate 设置资源来解决这个问题吗?

这是我一直在玩的无济于事:

    <Image Margin="25,4,14,46" 
           Name="MainImage" 
           Stretch="Uniform"
           MouseDown="MainImage_MouseDown" 
           Grid.Row="1" 
           HorizontalAlignment="Left"
           VerticalAlignment="Top"
           Source="{Binding Path=FileName}"
           >
        <Image.Resources>
            <DataTemplate DataType="{x:Type capp:CAPMeta}">
                <Label Content="{Binding Path=TagText}">
                </Label>
            </DataTemplate>
        </Image.Resources>                
    </Image>

谢谢!

I'm trying to add image tags to a WPF image and I'm not having much luck. I'd like to do it through databinding if at all possible. Can I set a resource with a DataTemplate to take care of this?

Here's what I've been playing with to no avail:

    <Image Margin="25,4,14,46" 
           Name="MainImage" 
           Stretch="Uniform"
           MouseDown="MainImage_MouseDown" 
           Grid.Row="1" 
           HorizontalAlignment="Left"
           VerticalAlignment="Top"
           Source="{Binding Path=FileName}"
           >
        <Image.Resources>
            <DataTemplate DataType="{x:Type capp:CAPMeta}">
                <Label Content="{Binding Path=TagText}">
                </Label>
            </DataTemplate>
        </Image.Resources>                
    </Image>

Thanks!

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

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

发布评论

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

评论(1

樱桃奶球 2024-09-12 20:41:34

好吧,我最终使用带有包含绑定文本的 ItemResources 的画布来解决此问题。

Well, I ended up using a canvas with ItemResources containing bound text to resolve this issue.

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