Hi all,
I'm a newbie in WPF and C#. I'm working on a small project and I want to make a custom window with borderless feature.
I did some googling on the internet and found a sample for that.
The problem is I didn't understand the code of the file.cs, and here is the first part of the code:
I'll post the second part of the code in the next post.
Please, can someone explain the for me?
I'll really appreciate the help.
Thanks!
I'm a newbie in WPF and C#. I'm working on a small project and I want to make a custom window with borderless feature.
I did some googling on the internet and found a sample for that.
The problem is I didn't understand the code of the file.cs, and here is the first part of the code:
PHP Code:
namespace Custom_Window_Chrome_Demo
{
public class ThemedWindow : System.Windows.Window
{
private Point cursorOffset;
private double restoreTop;
private FrameworkElement borderLeft;
private FrameworkElement borderTopLeft;
private FrameworkElement borderTop;
private FrameworkElement borderTopRight;
private FrameworkElement borderRight;
private FrameworkElement borderBottomRight;
private FrameworkElement borderBottom;
private FrameworkElement borderBottomLeft;
private FrameworkElement caption;
private FrameworkElement frame;
private Button minimizeButton;
private Button maximizeButton;
private Button closeButton;
private IntPtr handle;
public ThemedWindow()
{
SourceInitialized += (sender, e) =>
{
handle = new WindowInteropHelper(this).Handle;
HwndSource.FromHwnd(handle).AddHook(new HwndSourceHook(WndProc));
};
Style = (Style)TryFindResource("ThemedWindowStyle");
}
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
RegisterFrame();
RegisterBorders();
RegisterCaption();
RegisterMinimizeButton();
RegisterMaximizeButton();
RegisterCloseButton();
}
private void RegisterCloseButton()
{
closeButton = (Button)GetTemplateChild("PART_WindowCaptionCloseButton");
if (closeButton != null)
{
closeButton.Click += (sender, e) => Close();
}
}
private void RegisterMaximizeButton()
{
maximizeButton = (Button)GetTemplateChild("PART_WindowCaptionMaximizeButton");
if (maximizeButton != null)
{
maximizeButton.Click += (sender, e) =>
{
if (WindowState == System.Windows.WindowState.Normal)
{
WindowState = System.Windows.WindowState.Maximized;
}
else
{
WindowState = System.Windows.WindowState.Normal;
}
};
}
}
private void RegisterMinimizeButton()
{
minimizeButton = (Button)GetTemplateChild("PART_WindowCaptionMinimizeButton");
if (minimizeButton != null)
{
minimizeButton.Click += (sender, e) => WindowState = System.Windows.WindowState.Minimized;
}
}
Please, can someone explain the for me?
I'll really appreciate the help.
Thanks!