Skip to content

Commit 6efc189

Browse files
committed
fix: bind to TextDocument instead if custom binding behavior
1 parent 8e8e99d commit 6efc189

File tree

3 files changed

+24
-73
lines changed

3 files changed

+24
-73
lines changed

DocumentTextBindingBehavior.cs

Lines changed: 0 additions & 64 deletions
This file was deleted.

MainWindow.axaml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
xmlns="https://github.com/avaloniaui"
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
55
xmlns:AvaloniaEdit="clr-namespace:AvaloniaEdit;assembly=AvaloniaEdit"
6-
xmlns:behaviors="clr-namespace:SharpFM.Behaviors;assembly=SharpFM"
76
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
8-
xmlns:i="clr-namespace:Avalonia.Xaml.Interactivity;assembly=Avalonia.Xaml.Interactivity"
97
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
108
xmlns:vm="using:SharpFM.ViewModels"
119
Icon="/Assets/noun-sharp-teeth-monster-4226695.small.png"
@@ -169,7 +167,7 @@
169167
Text="Clip Content" />
170168
</Border>
171169

172-
<!-- AvaloniaEdit component (unchanged) -->
170+
<!-- AvaloniaEdit component with Document binding -->
173171
<Border
174172
Grid.Row="1"
175173
CornerRadius="0,0,8,8"
@@ -179,11 +177,8 @@
179177
FontFamily="Cascadia Code,Consolas,Menlo,Monospace"
180178
ShowLineNumbers="True"
181179
SyntaxHighlighting="Xml"
182-
WordWrap="False">
183-
<i:Interaction.Behaviors>
184-
<behaviors:DocumentTextBindingBehavior Text="{Binding SelectedClip.ClipXml, Mode=TwoWay}" />
185-
</i:Interaction.Behaviors>
186-
</AvaloniaEdit:TextEditor>
180+
WordWrap="False"
181+
Document="{Binding SelectedClip.XmlDocument}" />
187182
</Border>
188183
</Grid>
189184
</Border>

ViewModels/ClipViewModel.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.ComponentModel;
22
using System.Runtime.CompilerServices;
3+
using AvaloniaEdit.Document;
34

45
namespace SharpFM.ViewModels;
56

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

1516
public FileMakerClip Clip { get; set; }
17+
18+
private TextDocument? _xmlDocument;
1619

1720
public ClipViewModel(FileMakerClip clip)
1821
{
@@ -39,13 +42,30 @@ public string Name
3942
}
4043
}
4144

45+
public TextDocument XmlDocument
46+
{
47+
get
48+
{
49+
if (_xmlDocument == null)
50+
{
51+
_xmlDocument = new TextDocument(Clip.XmlData ?? string.Empty);
52+
}
53+
return _xmlDocument;
54+
}
55+
}
56+
4257
public string ClipXml
4358
{
44-
get => Clip.XmlData;
59+
get => _xmlDocument?.Text ?? Clip.XmlData;
4560
set
4661
{
4762
Clip.XmlData = value;
63+
if (_xmlDocument != null)
64+
{
65+
_xmlDocument.Text = value ?? string.Empty;
66+
}
4867
NotifyPropertyChanged();
68+
NotifyPropertyChanged(nameof(XmlDocument));
4969
}
5070
}
5171
}

0 commit comments

Comments
 (0)