Making AvalonEdit MVVM compatible

前端 未结 3 876
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-13 05:09

I\'m trying to make Avalon MVVM compatible in my WPF application. From googling, I found out that AvalonEdit is not MVVM friendly and I need to export the state of AvalonEdi

3条回答
  •  一个人的身影
    2020-12-13 05:36

    You can use the Document property from the editor and bind it to a property of your ViewModel.

    Here is the code for the view :

    
        
            

    And the code for the ViewModel :

    namespace AvalonEditIntegration.UI
    {
        using System.Windows;
        using System.Windows.Input;
        using ICSharpCode.AvalonEdit.Document;
    
        public class ViewModel
        {
            public ViewModel()
            {
                ShowCode = new DelegatingCommand(Show);
                Document = new TextDocument();
            }
    
            public ICommand ShowCode { get; private set; }
            public TextDocument Document { get; set; }
    
            private void Show()
            {
                MessageBox.Show(Document.Text);
            }
        }
    }
    

    source : blog nawrem.reverse

提交回复
热议问题