开发者

WPF : How to bind StackPanel height (which is auto) to ImageControl height?

I have stackPanel created in design (xmal) which has Auto height and width. Adding list of image controls dynamically in Code on Load to stackPanel. Now it works fine. But when i try to resize the window, though the stack panel gets 开发者_开发知识库resized due to auto, but not the image contrl.

How to bind the actualheight of stackpanel dynamically to image control height, (so when ever stakpanl height gets changed ,image control also should get changed !!).

thanks


Use a ViewBox

<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
    <Viewbox MaxWidth="500" MaxHeight="500" Name="vb1">
        <Image Source="tulip_farm.jpg"/>
    </Viewbox>    
</StackPanel>

How to: Apply Stretch Properties to the Contents of a Viewbox

Or you could use binding as below:

<StackPanel x:Name="MyStackPanel">
    <Image Source="C:\Users\Public\Pictures\Sample Pictures\Chrysanthemum.jpg" Stretch="Uniform" Height="{Binding ElementName=MyStackPanel, Path=ActualHeight}"></Image>
</StackPanel>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜