Skip to content

Instantly share code, notes, and snippets.

@blachniet
Created June 30, 2012 15:46
Show Gist options
  • Save blachniet/3024297 to your computer and use it in GitHub Desktop.
Save blachniet/3024297 to your computer and use it in GitHub Desktop.
blachniet-post_borderless-wpf-window
<Window x:Class="SimpleBorderlessWindow.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow"
Height="562"
Width="1000"
WindowStyle="None"
AllowsTransparency="True"
ResizeMode="CanResizeWithGrip">
<DockPanel>
<DockPanel DockPanel.Dock="Top">
<TextBlock DockPanel.Dock="Right"
VerticalAlignment="Center">
<Hyperlink Click="TriggerClose"
Style="{StaticResource WindowIconStyle}">r</Hyperlink>
</TextBlock>
<TextBlock DockPanel.Dock="Right"
VerticalAlignment="Center">
<Hyperlink Click="TriggerMinimize"
Style="{StaticResource WindowIconStyle}">0</Hyperlink>
</TextBlock>
<StatusBar Background="Transparent"
MouseDoubleClick="TriggerMaximize"
MouseMove="TriggerMoveWindow">
<TextBlock DockPanel.Dock="Left"
Text="SimpleBorderlessWindow"
FontSize="16"/>
</StatusBar>
</DockPanel>
<Grid>
<TextBlock Text="Window Content Here"
HorizontalAlignment="Center"
VerticalAlignment="Center" />
</Grid>
</DockPanel>
<Window.Resources>
<Style x:Key="WindowIconStyle"
TargetType="{x:Type Hyperlink}">
<Setter Property="FontFamily"
Value="Webdings" />
<Setter Property="FontSize"
Value="16" />
<Setter Property="Foreground"
Value="White" />
<Setter Property="TextBlock.TextDecorations"
Value="{x:Null}" />
<Setter Property="Cursor"
Value="{x:Null}" />
<Style.Triggers>
<Trigger Property="IsMouseOver"
Value="True">
<Setter Property="Foreground"
Value="#ED5326" />
</Trigger>
</Style.Triggers>
</Style>
</Window.Resources>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void TriggerMoveWindow(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
if (WindowState == System.Windows.WindowState.Maximized)
{
WindowState = System.Windows.WindowState.Normal;
double pct = PointToScreen(e.GetPosition(this)).X / System.Windows.SystemParameters.PrimaryScreenWidth;
Top = 0;
Left = e.GetPosition(this).X - (pct * Width);
}
DragMove();
}
}
private void TriggerMaximize(object sender, MouseButtonEventArgs e)
{
if (WindowState == System.Windows.WindowState.Maximized)
WindowState = System.Windows.WindowState.Normal;
else if (WindowState == System.Windows.WindowState.Normal)
WindowState = System.Windows.WindowState.Maximized;
}
private void TriggerClose(object sender, RoutedEventArgs e)
{
Close();
}
private void TriggerMinimize(object sender, RoutedEventArgs e)
{
WindowState = System.Windows.WindowState.Minimized;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment