How to move window without wpf fields without code

I am creating a WPF application with a borderless window. Using the MVVVM Template (using Caliburn.Micro) I do not have the code behind the file, but only with the XAML file.

In several posts, I found the following solution:

XAML:

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

Code behind:

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

Now I am looking for a solution to fully define this in XAML.

Any idea?

+4
c # wpf mvvm xaml caliburn.micro
Oct 02 '13 at 5:50 on
source share
5 answers

The solution I will talk about is not really recommended, but you can put your code directly into your XAML file as follows:

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

Check out this Codeproject article for more information on this!

+6
Oct 02 '13 at 12:29
source share

I think your best option is behavior.

http://wpftutorial.net/Behaviors.html

+1
Oct 02 '13 at 5:56
source share

You can download the Microsoft.Windows.Shell dll ( Link . You can find other download options from Google), which gives you the CaptionHeight property, which allows you to drag a window from its top (for example, a regular window).

+1
Oct 02 '13 at 6:43
source share
0
02 Oct '13 at 6:12
source share

I know that I'm a little late for this question, but this is what I use sometime now, and it works like a charm.

  DashboardViewModel viewModel; public DashboardView() { InitializeComponent(); viewModel = new DashboardViewModel(); viewModel.RequestClose += (s, e) => Application.Current.Dispatcher.Invoke(this.Close); viewModel.RequestMinimize += (s, e) => Application.Current.Dispatcher.Invoke(() => { this.WindowState = WindowState.Minimized; }); DataContext = viewModel; } 

and something like this in your view

  #region Public Event Handlers public event EventHandler<EventArgs> RequestClose; public event EventHandler<EventArgs> RequestMinimize; #endregion 

Using ICommand ...

  #region ICommand Members public ICommand CloseCommand { get; private set; } public ICommand MinimizeCommand { get; private set; } #endregion 

Set up commands ...

  private void SetupCommands() { CloseCommand = new RelayCommand(CloseApplication); MinimizeCommand = new RelayCommand(MinimizeApplication); } 

Here is the RelayCommand class.

 public class RelayCommand : ICommand { #region Private Readonly Properties private readonly Action<object> executeCommand; private readonly Predicate<object> canExecute; #endregion #region Constructors public RelayCommand(Action<object> execute) : this(execute, null) { } public RelayCommand(Action<object> execute, Predicate<object> canExecute) { if (execute == null) throw new ArgumentNullException("execute"); this.executeCommand = execute; this.canExecute = canExecute; } #endregion #region Public ICommand Members public bool CanExecute(object parameter) { return canExecute == null ? true : canExecute(parameter); } public event EventHandler CanExecuteChanged { add { CommandManager.RequerySuggested += value; } remove { CommandManager.RequerySuggested -= value; } } public void Execute(object parameter) { executeCommand(parameter); } #endregion } 

And some example methods ...

  private void MinimizeApplication(object obj) { RequestMinimize(this, new EventArgs()); } private void CloseApplication(object obj) { RequestClose(this, new EventArgs()); } 

Hope this helps!

0
Dec 31 '15 at 21:00
source share



All Articles