Instead, 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 :
<Window x:Class="AvalonEditIntegration.UI.View" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:AvalonEdit="clr-namespace:ICSharpCode.AvalonEdit;assembly=ICSharpCode.AvalonEdit" Title="Window1" WindowStartupLocation="CenterScreen" Width="500" Height="500"> <DockPanel> <Button Content="Show code" Command="{Binding ShowCode}" Height="50" DockPanel.Dock="Bottom" /> <AvalonEdit:TextEditor ShowLineNumbers="True" Document="{Binding Path=Document}" FontFamily="Consolas" FontSize="10pt" /> </DockPanel> </Window>
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); } } }
Aucun commentaire:
Enregistrer un commentaire