WPF Web Based

WPF Examples

WPF

WPF Projects

WPF Project

adplus-dvertising
ViewBox control in WPF Web Base
Previous Home Next

The Viewbox element automatically scales its content to fill the space available.the Viewbox control, which expands a control to fill the available space (while keeping the aspect ratio) but the control can assume absolute size. The view box could only have one child; else if a view box contains more than one child, an argument exception will be thrown. Viewbox and Viewport are the properties of ImageBursh, DrawingBrush, TileBrush and VisualBrush elements in Windows Presentation Foundation. With these two attributes we can crop images and shapes.

Example

Figure1: Real Image

Figure2: See the image after selecting an area in ViewBox Control.

.XAML CODE:

<Page x:Class="WpfBrowserApplication5.Page12"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Page12" Width="344">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="400" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="400" />
</Grid.ColumnDefinitions>
<Rectangle Grid.Row="0" Grid.Column="0">
<Rectangle.Fill>
<!-- Here By passing the four value in ViewBox I will select a 
area from Real Image-->
<ImageBrush ImageSource="main_flash.jpg" Viewbox="0.4,0.12,0.7,0.8" />
</Rectangle.Fill>
</Rectangle>
</Grid>
</Page>

After set the property Stretch="Uniform" of image we will get:

Previous Home Next
WPF Examples

WPF

WPF

WPF

WPF

WPF

WPF

WPF

WPF