Transparent Window
<Window x:Class="Windows.ModernWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="ModernWindow" Height="300" Width="300"
AllowsTransparency="True" Background="Transparent"
WindowStyle="None" ResizeMode="CanResizeWithGrip">
<Border Width="Auto" Height="Auto" Name="windowFrame"
BorderBrush="#395984"
BorderThickness="1"
CornerRadius="0,20,30,40" >
<Border.Background>
<LinearGradientBrush >
<GradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#E7EBF7" Offset="0.0"/>
<GradientStop Color="#CEE3FF" Offset="0.5"/>
</GradientStopCollection>
</GradientBrush.GradientStops>
</LinearGradientBrush>
</Border.Background>
<StackPanel>
<TextBlock Text="Title Bar" Margin="1" Padding="5" MouseLeftButtonDown="titleBar_MouseLeftButtonDown"></TextBlock>
<Button Click="cmdClose_Click">Close</Button>
<Rectangle Cursor="SizeWE"
MouseLeftButtonDown="window_initiateWiden"
MouseLeftButtonUp="window_endWiden"
MouseMove="window_Widen"/>
</StackPanel>
</Border>
</Window>
//File:Window.xaml.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace Windows
{
public partial class ModernWindow : System.Windows.Window
{
public ModernWindow()
{
InitializeComponent();
}
bool isWiden = false;
private void window_initiateWiden(object sender, System.Windows.Input.MouseEventArgs e)
{
isWiden = true;
}
private void window_endWiden(object sender, System.Windows.Input.MouseEventArgs e)
{
isWiden = false;
Rectangle rect = (Rectangle)sender;
rect.ReleaseMouseCapture();
}
private void window_Widen(object sender, System.Windows.Input.MouseEventArgs e)
{
Rectangle rect = (Rectangle)sender;
if (isWiden)
{
rect.CaptureMouse();
double newWidth = e.GetPosition(this).X + 5;
if (newWidth > 0) this.Width = newWidth;
}
}
private void titleBar_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
this.DragMove();
}
private void cmdClose_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
}
}
Related examples in the same category