Closed sn4k3 closed 2 years ago
Any updates?
There is a PR to fix this problem https://github.com/AvaloniaUI/Avalonia/pull/4722
But it is better to solve problem with TwoWay bindings instead, because current DataGrid clipboard implementation should "just work" https://github.com/AvaloniaUI/Avalonia/issues/4721
Yeah, I saw these PRs/issues, maybe there is some workaround for now?
Answering to myself, an obvious one:
ClipboardCopyMode
to None
KeyUp
(or similar) event and write logic thereFurther note:
I'm also getting this: System.NotSupportedException: 'Two way bindings are not supported with a string format'
at Avalonia.Data.Converters.StringFormatValueConverter.ConvertBack(Object value, Type targetType, Object parameter, CultureInfo culture) in /_/src/Avalonia.Base/Data/Converters/StringFormatValueConverter.cs:line 46
at Avalonia.Data.Core.BindingExpression.OnNext(Object value) in /_/src/Avalonia.Base/Data/Core/BindingExpression.cs:line 129
at Avalonia.Reactive.LightweightObservableBase`1.Subscribe(IObserver`1 observer) in /_/src/Avalonia.Base/Reactive/LightweightObservableBase.cs:line 67
at Avalonia.Data.BindingOperations.Apply(IAvaloniaObject target, AvaloniaProperty property, InstancedBinding binding, Object anchor) in /_/src/Avalonia.Base/Data/BindingOperations.cs:line 88
at Avalonia.AvaloniaObjectExtensions.Bind(IAvaloniaObject target, AvaloniaProperty property, IBinding binding, Object anchor) in /_/src/Avalonia.Base/AvaloniaObjectExtensions.cs:line 377
at Avalonia.Controls.DataGridColumn.GetCellValue(Object item, IBinding binding) in /_/src/Avalonia.Controls.DataGrid/DataGridColumn.cs:line 591
at Avalonia.Controls.DataGrid.ProcessCopyKey(KeyModifiers modifiers) in /_/src/Avalonia.Controls.DataGrid/DataGrid.cs:line 5967
at Avalonia.Controls.DataGrid.ProcessDataGridKey(KeyEventArgs e) in /_/src/Avalonia.Controls.DataGrid/DataGrid.cs:line 4598
at Avalonia.Controls.DataGrid.DataGrid_KeyDown(Object sender, KeyEventArgs e) in /_/src/Avalonia.Controls.DataGrid/DataGrid.cs:line 3828
at Avalonia.Interactivity.EventRoute.RaiseEventImpl(RoutedEventArgs e) in /_/src/Avalonia.Interactivity/EventRoute.cs:line 152
at Avalonia.Interactivity.EventRoute.RaiseEvent(IInteractive source, RoutedEventArgs e) in /_/src/Avalonia.Interactivity/EventRoute.cs:line 102
at Avalonia.Interactivity.Interactive.RaiseEvent(RoutedEventArgs e) in /_/src/Avalonia.Interactivity/Interactive.cs:line 122
at Avalonia.Input.KeyboardDevice.ProcessRawEvent(RawInputEventArgs e) in /_/src/Avalonia.Input/KeyboardDevice.cs:line 248
at Avalonia.Input.InputManager.ProcessInput(RawInputEventArgs e) in /_/src/Avalonia.Input/InputManager.cs:line 36
at Avalonia.Win32.WindowImpl.AppWndProc(IntPtr hWnd, UInt32 msg, IntPtr wParam, IntPtr lParam) in /_/src/Windows/Avalonia.Win32/WindowImpl.AppWndProc.cs:line 482
at Avalonia.Win32.WindowImpl.WndProc(IntPtr hWnd, UInt32 msg, IntPtr wParam, IntPtr lParam) in /_/src/Windows/Avalonia.Win32/WindowImpl.WndProc.cs:line 33
at Avalonia.Win32.Interop.UnmanagedMethods.DispatchMessage(MSG& lpmsg)
at Avalonia.Win32.Win32Platform.RunLoop(CancellationToken cancellationToken) in /_/src/Windows/Avalonia.Win32/Win32Platform.cs:line 194
at Avalonia.Threading.Dispatcher.MainLoop(CancellationToken cancellationToken) in /_/src/Avalonia.Base/Threading/Dispatcher.cs:line 62
at Avalonia.Controls.ApplicationLifetimes.ClassicDesktopStyleApplicationLifetime.Start(String[] args) in /_/src/Avalonia.Controls/ApplicationLifetimes/ClassicDesktopStyleApplicationLifetime.cs:line 127
at Avalonia.ClassicDesktopStyleApplicationLifetimeExtensions.StartWithClassicDesktopLifetime[T](T builder, String[] args, ShutdownMode shutdownMode) in /_/src/Avalonia.Controls/ApplicationLifetimes/ClassicDesktopStyleApplicationLifetime.cs:line 175
at UVtools.WPF.Program.Main(String[] args) in D:\Tiago\Dropbox\Programming\C#\UVtools\UVtools.WPF\Program.cs:line 49
When using this property as bidding:
public IEnumerable IssuesGridItems
{
get
{
if (!IsFileLoaded || DataContext is null) return null;
if (Settings.Issues.DataGridGroupByType || Settings.Issues.DataGridGroupByLayerIndex)
{
var groupView = new DataGridCollectionView(SlicerFile.IssueManager);
if (Settings.Issues.DataGridGroupByType) groupView.GroupDescriptions.Add(new DataGridPathGroupDescription("Type"));
if (Settings.Issues.DataGridGroupByLayerIndex) groupView.GroupDescriptions.Add(new DataGridPathGroupDescription("StartLayerIndex"));
return groupView;
}
return SlicerFile.IssueManager;
}
}
Wont happen if i feed DataGrid.Items="{Binding SlicerFile.IssueManager}" directly on XAMAL
Hey @sn4k3 if you're still looking for a solution, you can set ClipboardContentBinding
and this will let the copy command work as expected.
Happy coding, Tim
/cc @FoggyFinder
Hey @sn4k3 if you're still looking for a solution, you can set
ClipboardContentBinding
and this will let the copy command work as expected.
Any sample arround that?
Sure
<DataGrid Items="{Binding MyItems}">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Title}"
ClipboardContentBinding="{Binding Title}"
Header="Title" />
[ ... ]
</DataGrid.Columns>
</DataGrid>
When copy data with Ctrl + C all selected rows are emptied Data is copied to clipboard as expected
Version: 0.10.0-preview5
Before Copy:
2 row copied
Ctrl + A & Ctrl +C