OverviewFilesCommitsIssuesDocsReleasesPeers

ifsrenderer-linux / WpfDisplay / Views / EditorWindow.xaml.cs

57 lines · csharp ref:
using System;
using System.Windows;
using System.Windows.Input;
using System.Windows.Interop;

using WpfDisplay.Services;
using WpfDisplay.ViewModels;

namespace WpfDisplay.Views;

/// <summary>
/// Interaction logic for EditorWindow.xaml
/// </summary>
public partial class EditorWindow : Window
{
    private IFSViewModel vm => (IFSViewModel)DataContext;

    public EditorWindow()
    {
        InitializeComponent();
        MaterialDesignThemes.Wpf.ShadowAssist.SetCacheMode(this, null);//disable gpu cache
    }

    //fix laggy ui by disabling wpf hardware rendering
    protected override void OnSourceInitialized(EventArgs e)
    {
        if (PresentationSource.FromVisual(this) is HwndSource hwndSource)
        {
            hwndSource.CompositionTarget.RenderMode = RenderMode.SoftwareOnly;
        }

        base.OnSourceInitialized(e);
    }

    private void Undo_Executed(object sender, ExecutedRoutedEventArgs e) => vm.UndoCommand.Execute(null);

    private void Undo_CanExecute(object sender, CanExecuteRoutedEventArgs e) => e.CanExecute = vm?.UndoCommand.CanExecute(null) ?? false;

    private void Redo_Executed(object sender, ExecutedRoutedEventArgs e) => vm.RedoCommand.Execute(null);

    private void Redo_CanExecute(object sender, CanExecuteRoutedEventArgs e) => e.CanExecute = vm?.RedoCommand.CanExecute(null) ?? false;

    private void editorWindow_DragOver(object sender, DragEventArgs e)
    {
        e.Handled = true;
        e.Effects = FileDropHandler.GetDragDropEffect(e.Data);
    }

    private void editorWindow_Drop(object sender, DragEventArgs e)
    {
        e.Handled = true;
        var mainvm = (MainViewModel)Application.Current.MainWindow.DataContext;//uff
        mainvm.DropFileCommand.Execute(e.Data);
    }

}