Add the width and height properties to your XAML
<Image
Style="{StaticResource ImageStyle}"
Stretch="Uniform"
Source="{Binding ImageName}"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Margin="1,1,1,1"
Width="{Binding imageWidth}" Height="{Binding imageHeight}"
/>
In your backend code you need to create the two properties that you are binding too.
private int _imageWidth;
public int imageWidth{
get{ return _imageWidth; }
set{ _imageWidth = value; OnPropertyChanged("imageWidth"); }
}
private int _imageHeight;
public int imageHeight{
get{ return _imageHeight; }
set{ _imageHeight = value; OnPropertyChanged("imageHeight");}
}
You will also need to have INotifyPropertyChanged
implemented in your class
public class YourClassName : INotifyPropertyChanged //Hold control and hit period to add the using for this
{
PropertyChangedEventHandler PropertyChanged;
void OnPropertyChanged(String prop){
PropertyChangedEventHandler handler = PropertyChanged;
if(handler!=null){
PropertyChanged(this, new PropertyChangedEventArgs(prop));
}
}
}
When this is all wired up all you have to do is set the imageWidth and imageHeight properties when you get the values. It will automatically change it in the UI.