Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to move borderless wpf window without code behind file

I'm creating a WPF application with a borderless window. Applying the MVVVM pattern (with help of Caliburn.Micro) I do not have a code behind file but only a XAML file.

In several posts I found following solution:

XAML:

<Window
   ...
   WindowStyle="None" MouseLeftButtonDown="WindowMouseLeftButtonDown"/>

Code behind:

 private void WindowMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        DragMove();
    }

Now I'm searching a solution to define this completely in XAML.

Any idea?

like image 996
rhe1980 Avatar asked Oct 02 '13 05:10

rhe1980


1 Answers

The solution I will present is not really advised, but you can put your code behind right in your XAML file like this:

<Window
...
WindowStyle="None" MouseLeftButtonDown="WindowMouseLeftButtonDown"/>
<x:Code>
    <![CDATA[            
        private void WindowMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            DragMove();
        }
    ]]>
</x:Code>

Check this Codeproject article for more information on this!

like image 52
Ibrahim Najjar Avatar answered Sep 29 '22 06:09

Ibrahim Najjar