IsReadOnly propertyChange fix
MODIFY
WalletWasabi.Gui/Controls/ExtendedTextBox.cs
WalletWasabi.Gui/Controls/ExtendedTextBox.cs
@@ -13,7 +13,7 @@ namespace WalletWasabi.Gui.Controls
{
public class ExtendedTextBox : TextBox, IStyleable
{
- private MenuItem _pasteItem;
+ private MenuItem _pasteItem = null;
public ExtendedTextBox()
{
@@ -27,27 +27,27 @@ namespace WalletWasabi.Gui.Controls
PasteAsync();
});
- this.GetObservable(IsReadOnlyProperty).Subscribe(ro =>
- {
- if (!(_pasteItem is null))
+ this.GetObservable(IsReadOnlyProperty).Subscribe(isReadOnly =>
{
+ if (ContextMenu == null) return;
var items = ContextMenu.Items as Avalonia.Controls.Controls;
- if (ro)
+ if (isReadOnly)
{
if (items.Contains(_pasteItem))
{
items.Remove(_pasteItem);
+ _pasteItem = null;
}
}
else
{
if (!items.Contains(_pasteItem))
{
+ CreatePasteItem();
items.Add(_pasteItem);
}
}
- }
});
}
@@ -136,6 +136,14 @@ namespace WalletWasabi.Gui.Controls
if (!IsReadOnly)
{
+ CreatePasteItem();
+ (ContextMenu.Items as Avalonia.Controls.Controls).Add(_pasteItem);
+ }
+ }
+
+ private void CreatePasteItem()
+ {
+ if (_pasteItem != null) return;
var pastePresenter = new DrawingPresenter
{
Drawing = new GeometryDrawing
@@ -148,8 +156,7 @@ namespace WalletWasabi.Gui.Controls
Width = 16,
Height = 16,
};
- (ContextMenu.Items as Avalonia.Controls.Controls).Add(new MenuItem { Header = "Paste", Command = PasteCommand, Icon = pastePresenter });
- }
+ _pasteItem = new MenuItem { Header = "Paste", Command = PasteCommand, Icon = pastePresenter };
}
}
}

IsReadOnly propertyChange fix