Search This Blog

Wednesday, October 30, 2013

WPF Window

WPF > Controls  > ContentControl > Window

A Windows Presentation Foundation (WPF) Window represents interaction between a user and a standalone application.
WPF window has two areas:
  • A non-client area (title, icon, buttons, border)
  • A client area (application content)

WPF Window Example:

In this example we will create a transparent window with opacity of 80%.

XAML:

<Window x:Class="ButtonExample.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525" Opacity="0.8" AllowsTransparency="True" WindowStyle="None" Background="#FFEEE4E4"
        WindowStartupLocation="CenterScreen">
    <Grid>
        <Button Content="Close" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Click="Button_Click"/>
    </Grid>
</Window>

C# Code:

private void Button_Click(object sender, RoutedEventArgs e)
{  
  this.Close();
}