You seem to be setting a width and height in your code behind... this is the size that the Image
will be. Instead of this, try setting the Image.Source
property in xaml:
<UserControl x:Class="WpfApplication1.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Image Source="/WpfApplication1;component/Images/ImageName.png" />
</Grid>
</UserControl>
If I put this into MainWindow.xaml
, the Image
resizes when resizing the Window.
If you need to set the URL of the Image
in code, then you can add a property in your view model, bind it to the Source
property and change that to the new path in code instead:
<Image Source="{Binding ViewModelSourceProperty}" /> // don't set size here
I hope that helps.