Borrowing from what I found here I came up with:
Inside the image tag in XAML, do:
<Image.Resources> <c:StringJoinConverter x:Key="StringJoin" /> </Image.Resources> <Image.Tag> <MultiBinding Converter="{StaticResource StringJoin}"> <Binding RelativeSource="{RelativeSource Self}" Path="Source.PixelWidth" /> <Binding RelativeSource="{RelativeSource Self}" Path="Source.PixelHeight" /> </MultiBinding> </Image.Tag>
You will need to configure the namespace c at the top of your XAML file for your folder / Converter namespace, for example:
xmlns:c="clr-namespace:Project.Converters"
Then create a converter:
public class StringJoinConverter : IMultiValueConverter { public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { return string.Join((parameter ?? ",").ToString(), values); } public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) { throw new NotImplementedException(); } }
Then you can extract the actual (pixel) width and height of the image with:
var tag = imageControl.Tag;
source share