Quantcast
Channel: VBForums - WPF, WCF, WF
Viewing all articles
Browse latest Browse all 256

WPF Code

$
0
0
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:

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 += (sendere) =>
            {
                
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 += (sendere) => Close();
            }
        }
        private 
void RegisterMaximizeButton()
        {
            
maximizeButton = (Button)GetTemplateChild("PART_WindowCaptionMaximizeButton");
            if (
maximizeButton != null)
            {
                
maximizeButton.Click += (sendere) =>
                {
                    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 += (sendere) => WindowState System.Windows.WindowState.Minimized;
            }
        } 

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!

Viewing all articles
Browse latest Browse all 256

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>