Reputation: 22744
This is similar to how-do-i-keep-aspect-ratio-on-scalable-scrollable-content-in-wpf, with the following differences:
Upvotes: 0
Views: 1763
Reputation: 19851
You just need to bind one of the parameters Width
or Height
to the other:
<Image x:Name="image" Height="{Binding Width, ElementName=image}"/>
Upvotes: 1
Reputation: 8940
You should bind Grid's Width and Height to one value:
<!--Dont forget to specify source where MaxSizeParam lies-->
<Grid Width="{Binding MaxSizeParam}" Height="{Binding MaxSizeParam}"/>
MaxSizeParam you can provide wherever you want an in what manner you want. For example if grid has Button then on SizeChanged event of Button you should recalculate MaxSizeParam:
void button_SizeChanged(object sender, SizeChangedEventArgs e)
{
MaxSizeParam = e.NewSize.Width > e.NewSize.Height ? e.NewSize.Width : e.NewSize.Height;
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs("MaxSizeParam"));
}
Upvotes: 1