Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 0 additions & 64 deletions DocumentTextBindingBehavior.cs

This file was deleted.

11 changes: 3 additions & 8 deletions MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:AvaloniaEdit="clr-namespace:AvaloniaEdit;assembly=AvaloniaEdit"
xmlns:behaviors="clr-namespace:SharpFM.Behaviors;assembly=SharpFM"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:i="clr-namespace:Avalonia.Xaml.Interactivity;assembly=Avalonia.Xaml.Interactivity"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vm="using:SharpFM.ViewModels"
Icon="/Assets/noun-sharp-teeth-monster-4226695.small.png"
Expand Down Expand Up @@ -169,7 +167,7 @@
Text="Clip Content" />
</Border>

<!-- AvaloniaEdit component (unchanged) -->
<!-- AvaloniaEdit component with Document binding -->
<Border
Grid.Row="1"
CornerRadius="0,0,8,8"
Expand All @@ -179,11 +177,8 @@
FontFamily="Cascadia Code,Consolas,Menlo,Monospace"
ShowLineNumbers="True"
SyntaxHighlighting="Xml"
WordWrap="False">
<i:Interaction.Behaviors>
<behaviors:DocumentTextBindingBehavior Text="{Binding SelectedClip.ClipXml, Mode=TwoWay}" />
</i:Interaction.Behaviors>
</AvaloniaEdit:TextEditor>
WordWrap="False"
Document="{Binding SelectedClip.XmlDocument}" />
</Border>
</Grid>
</Border>
Expand Down
22 changes: 21 additions & 1 deletion ViewModels/ClipViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.ComponentModel;
using System.Runtime.CompilerServices;
using AvaloniaEdit.Document;

namespace SharpFM.ViewModels;

Expand All @@ -13,6 +14,8 @@ private void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
}

public FileMakerClip Clip { get; set; }

private TextDocument? _xmlDocument;

public ClipViewModel(FileMakerClip clip)
{
Expand All @@ -39,13 +42,30 @@ public string Name
}
}

public TextDocument XmlDocument
{
get
{
if (_xmlDocument == null)
{
_xmlDocument = new TextDocument(Clip.XmlData ?? string.Empty);
}
return _xmlDocument;
}
}

public string ClipXml
{
get => Clip.XmlData;
get => _xmlDocument?.Text ?? Clip.XmlData;
set
{
Clip.XmlData = value;
if (_xmlDocument != null)
{
_xmlDocument.Text = value ?? string.Empty;
}
NotifyPropertyChanged();
NotifyPropertyChanged(nameof(XmlDocument));
}
}
}
Loading