WPF: view that scales to container at large sizes, scrolls at small sizes?
I am building a control depicting a diagram. The control's content (which is rather com开发者_开发问答plex) will try to scale to fit allotted space to the extent possible. However, not all scales are valid. The content cannot shrink indefinitely. E.g. a box on a diagram should be at least 20 pixels wide. Thus, when the window is too small to fit the content even at the minimum size, scaling should stop and scroll bars must appear.
I cannot find an elegant solution for this in WPF. Any design ideas are greatly appreciated.
Set the Horizontal & VerticalAlignment of the content to Stretch but also set the MinWidth and MinHeight to appropriate values, place your content in a ScrollViewer whose Horizontal & VerticalScrollBarVisibility is set to Auto.
That should work, probably...
Example:
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
<Button
MinHeight="400"
MinWidth="400"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Content="Buttons!"/>
</ScrollViewer>
</Window>
加载中,请稍侯......
精彩评论