MainPage.xaml
<Page
x:Class="UniversalAppTutorials.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UniversalAppTutorials"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<StackPanel
x:Name="StackPanel1"
Margin="50"
Orientation="Vertical"
Background="AliceBlue"
Padding="50"
>
<!---
Stretch
Fill
The content is resized to fill the destination dimensions.
The aspect ratio is not preserved.
None
The content preserves its original size.
Uniform
The content is resized to fit in the destination
dimensions while it preserves its native aspect ratio.
It is the default setting of Stretch.
UniformToFill
The content is resized to fill the destination dimensions while
it preserves its native aspect ratio. If the aspect ratio of the
destination rectangle differs from the source, the source
content is clipped to fit in the destination dimensions.
-->
<Viewbox MaxWidth="300" MaxHeight="100" Stretch="Fill" Margin="10">
<Button Content="Stretch Fill"/>
</Viewbox>
<Viewbox MaxWidth="300" MaxHeight="100" Stretch="None" Margin="10">
<Button Content="Strecth None"/>
</Viewbox>
<Viewbox MaxWidth="300" MaxHeight="100" Stretch="Uniform" Margin="10">
<Button Content="Stretch Uniform"/>
</Viewbox>
<Viewbox MaxWidth="300" MaxHeight="100" Stretch="UniformToFill" Margin="10">
<Button Content="UniformToFill"/>
</Viewbox>
</StackPanel>
</Page>
MainPage.xaml.cs
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Media;
namespace UniversalAppTutorials
{
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
// Initialize a new Viewbox instance
Viewbox viewbox = new Viewbox();
// Set the Viewbox maximum width and height
// This will resize the inside content
viewbox.MaxWidth = 300;
viewbox.MaxHeight = 100;
// Set the margin of Viewbox
viewbox.Margin = new Thickness(10);
// Set the Viewbox Stretch programmatically
viewbox.Stretch = Stretch.Fill;
// Set the Viewbox Stretch direction
viewbox.StretchDirection = StretchDirection.Both;
// Initialize a new Button
Button button = new Button();
button.Content = "Stretch In Code";
// Put the Button inside Viewbox
viewbox.Child = button;
// Finally, put the Viewbox on stack panel
StackPanel1.Children.Add(viewbox);
}
}
}

- UWP - ScrollViewer example
- UWP - RelativePanel example
- UWP - How to make TextBlock text selectable
- UWP - How to use TextBox SelectionChanged event
- UWP - Select TextBox all text when get focus
- UWP - How to create a multiline TextBox
- UWP - Simple FlipView example
- UWP - How to exit an app
- UWP - How to set app window minimum size
- UWP - Get app screen size
- UWP - Segoe MDL2 Assets programmatically
- UWP - Segoe MDL2 Assets font example
- UWP - SplitView example
- UWP - Viewbox example
- UWP - How to resize SymbolIcon