代码之家  ›  专栏  ›  技术社区  ›  Noah

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

  •  0
  • Noah  · 技术社区  · 15 年前

    我试图添加图像标签到一个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>
    

    1 回复  |  直到 15 年前
        1
  •  0
  •   Noah    15 年前

    好吧,我最终使用了一个包含绑定文本的ItemResources画布来解决这个问题。