Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 如何在工具提示中获取图像属性_Wpf_Image_Tooltip - Fatal编程技术网

Wpf 如何在工具提示中获取图像属性

Wpf 如何在工具提示中获取图像属性,wpf,image,tooltip,Wpf,Image,Tooltip,我有一个任务是在工具提示中获取图像类型、尺寸和大小。我试着使用这个代码。我获取了图像url,无法获取工具提示中的图像属性 <Image Source="{Binding Path=UriSource}" Stretch="Fill" Width="100" Height="120"> <Image.ToolTip> <ToolTip Content="{Binding}"/> </Image.ToolTip> &

我有一个任务是在工具提示中获取图像类型、尺寸和大小。我试着使用这个代码。我获取了图像url,无法获取工具提示中的图像属性

 <Image Source="{Binding Path=UriSource}" Stretch="Fill" Width="100" Height="120">
    <Image.ToolTip>
         <ToolTip Content="{Binding}"/>
    </Image.ToolTip>
</Image>


如何在工具提示WPF中获取图像尺寸?

如果要获取父控件的属性,必须设置
工具提示的
DataContext

    <Image Source="face-monkey.png" Width="60">
        <Image.ToolTip>
            <ToolTip DataContext="{Binding Path=PlacementTarget, RelativeSource={x:Static RelativeSource.Self}}">
                <StackPanel Orientation="Horizontal">
                    <Label Content="Width:" FontWeight="Bold"/>
                    <Label Content="{Binding Width}"/>
                </StackPanel>
            </ToolTip>
        </Image.ToolTip>
    </Image>


如果要获取父控件的属性,必须设置
工具提示的
DataContext

    <Image Source="face-monkey.png" Width="60">
        <Image.ToolTip>
            <ToolTip DataContext="{Binding Path=PlacementTarget, RelativeSource={x:Static RelativeSource.Self}}">
                <StackPanel Orientation="Horizontal">
                    <Label Content="Width:" FontWeight="Bold"/>
                    <Label Content="{Binding Width}"/>
                </StackPanel>
            </ToolTip>
        </Image.ToolTip>
    </Image>


由于绑定源对象似乎是BitmapSource,因此可以直接绑定到其属性,例如其像素宽度和像素高度:

<Image Source="{Binding}" Width="100" Height="120">
    <Image.ToolTip>
        <ToolTip Content="{Binding}">
            <ToolTip.ContentTemplate>
                <DataTemplate>
                    <StackPanel>
                        <TextBlock Text="{Binding PixelWidth, StringFormat=Width: {0}}"/>
                        <TextBlock Text="{Binding PixelHeight, StringFormat=Height: {0}}"/>
                    </StackPanel>
                </DataTemplate>
            </ToolTip.ContentTemplate>
        </ToolTip>
    </Image.ToolTip>
</Image>

由于绑定源对象似乎是BitmapSource,因此可以直接绑定到其属性,例如其PixelWidth和PixelHeight:

<Image Source="{Binding}" Width="100" Height="120">
    <Image.ToolTip>
        <ToolTip Content="{Binding}">
            <ToolTip.ContentTemplate>
                <DataTemplate>
                    <StackPanel>
                        <TextBlock Text="{Binding PixelWidth, StringFormat=Width: {0}}"/>
                        <TextBlock Text="{Binding PixelHeight, StringFormat=Height: {0}}"/>
                    </StackPanel>
                </DataTemplate>
            </ToolTip.ContentTemplate>
        </ToolTip>
    </Image.ToolTip>
</Image>

我有100张照片。从web加载。我不知道宽度和高度。我有100张图片。从web加载。我不知道宽度和高度。请注意,
Source=“{Binding Path=UriSource}”
首先是错误的
Path=UriSource
表示绑定源对象已经是位图图像。但是,绑定通过从Uri到ImageSource的内置类型转换创建另一个BitmapFrame。绑定应该是这样的:
Source=“{Binding}”
Urisource是位图图像的集合。当然,因为Urisource是集合中单个位图图像的属性,所以您只需执行
Source=“{Binding}”
。这就是说,我们根本不清楚“图像类型、尺寸和大小”应该是什么。虽然尺寸和大小似乎意味着同一件事,但图像类型尚不清楚。你是指位图图像的像素宽度和像素高度吗?使用给定的答案可以在图像标记中显示宽度。不获取图像的原始大小请注意,
Source=“{Binding Path=UriSource}”
首先是错误的
Path=UriSource
表示绑定源对象已经是位图图像。但是,绑定通过从Uri到ImageSource的内置类型转换创建另一个BitmapFrame。绑定应该是这样的:
Source=“{Binding}”
Urisource是位图图像的集合。当然,因为Urisource是集合中单个位图图像的属性,所以您只需执行
Source=“{Binding}”
。这就是说,我们根本不清楚“图像类型、尺寸和大小”应该是什么。虽然尺寸和大小似乎意味着同一件事,但图像类型尚不清楚。你是指位图图像的像素宽度和像素高度吗?使用给定的答案可以在图像标记中显示宽度。不获取图像的原始大小