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
1 change: 1 addition & 0 deletions samples/WinUI.TableView.SampleApp/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ private void OnNavigationSelectionChanged(NavigationView sender, NavigationViewS
"Filtering" => typeof(FilteringPage),
"Customize Filter Flyout" => typeof(CustomizeFilterPage),
"External Filtering" => typeof(ExternalFilteringPage),
"Clipboard Actions" => typeof(ClipboardActionsPage),
"Editing" => typeof(EditingPage),
"Sorting" => typeof(SortingPage),
"Custom Sorting" => typeof(CustomizeSortingPage),
Expand Down
51 changes: 51 additions & 0 deletions samples/WinUI.TableView.SampleApp/Pages/ClipboardActionsPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<Page x:Class="WinUI.TableView.SampleApp.Pages.ClipboardActionsPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:controls="using:WinUI.TableView.SampleApp.Controls"
xmlns:local="using:WinUI.TableView.SampleApp"
xmlns:tv="using:WinUI.TableView"
d:DataContext="{d:DesignInstance Type=local:ExampleViewModel}"
mc:Ignorable="d">

<Grid>
<controls:SamplePresenter Header="Clipboard Actions">
<controls:SamplePresenter.Description>
<x:String xml:space="preserve">Use Ctrl+C, Ctrl+Shift+C or the corner options menu to copy the current selection.
Paste tab-delimited data from Excel with Ctrl+V or the same menu.</x:String>
</controls:SamplePresenter.Description>
<controls:SamplePresenter.Example>
<tv:TableView x:Name="tableView"
CanCopy="{x:Bind canCopyToggle.IsOn, Mode=TwoWay}"
CanPaste="{x:Bind canPasteToggle.IsOn, Mode=TwoWay}"
ItemsSource="{Binding Items}"
AutoGeneratingColumn="{x:Bind local:ExampleModelColumnsHelper.OnAutoGeneratingColumns}" />
</controls:SamplePresenter.Example>
<controls:SamplePresenter.Options>
<StackPanel Spacing="8">
<ToggleSwitch x:Name="canCopyToggle"
Header="Can Copy"
IsOn="True" />
<ToggleSwitch x:Name="canPasteToggle"
Header="Can Paste"
IsOn="True" />
</StackPanel>
</controls:SamplePresenter.Options>
<controls:SamplePresenter.Xaml>
<x:String xml:space="preserve">
&lt;tv:TableView x:Name="tableView"
CanCopy="$(CanCopy)"
CanPaste="$(CanPaste)"
ItemsSource="{Binding Items}" />
</x:String>
</controls:SamplePresenter.Xaml>
<controls:SamplePresenter.Substitutions>
<controls:CodeSubstitution Key="CanCopy"
Value="{x:Bind tableView.CanCopy, Mode=OneWay}" />
<controls:CodeSubstitution Key="CanPaste"
Value="{x:Bind tableView.CanPaste, Mode=OneWay}" />
</controls:SamplePresenter.Substitutions>
</controls:SamplePresenter>
</Grid>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using System.Collections.ObjectModel;
using Windows.ApplicationModel.DataTransfer;

namespace WinUI.TableView.SampleApp.Pages;

public sealed partial class ClipboardActionsPage : Page
{
public ClipboardActionsPage()
{
InitializeComponent();
}
}
60 changes: 50 additions & 10 deletions src/Columns/TableViewColumn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.UI.Xaml.Data;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using WinUI.TableView.Extensions;
using SD = WinUI.TableView.SortDirection;

Expand All @@ -14,8 +15,9 @@ namespace WinUI.TableView;
[StyleTypedProperty(Property = nameof(CellStyle), StyleTargetType = typeof(TableViewCell))]
public abstract partial class TableViewColumn : DependencyObject
{
private Func<object, object?>? _funcCompiledPropertyPath;
private Func<object, object?>? _funcCompiledClipboardPropertyPath;
private Func<object, object?>? _compliedValueGetter;
private Func<object, object?>? _compliedClipboardValueGetter;
private Action<object, object?>? _compliedClipboardValueSetter;

/// <summary>
/// Initializes a new instance of the <see cref="TableViewColumn"/> class with default conditional cell styles.
Expand Down Expand Up @@ -106,11 +108,11 @@ internal void SetOwningTableView(TableView tableView)
if (dataItem is null)
return null;

if (_funcCompiledPropertyPath is null && !string.IsNullOrWhiteSpace(OperationContentBindingPropertyPath))
_funcCompiledPropertyPath = dataItem.GetFuncCompiledPropertyPath(OperationContentBindingPropertyPath!);
if (_compliedValueGetter is null && !string.IsNullOrWhiteSpace(OperationContentBindingPropertyPath))
_compliedValueGetter = dataItem.GetCompiledValueGetter(OperationContentBindingPropertyPath!);

if (_funcCompiledPropertyPath is not null)
dataItem = _funcCompiledPropertyPath(dataItem);
if (_compliedValueGetter is not null)
dataItem = _compliedValueGetter(dataItem);

if (OperationContentBinding?.Converter is not null)
{
Expand All @@ -134,11 +136,11 @@ internal void SetOwningTableView(TableView tableView)
if (dataItem is null)
return null;

if (_funcCompiledClipboardPropertyPath is null && !string.IsNullOrWhiteSpace(ClipboardContentBindingPropertyPath))
_funcCompiledClipboardPropertyPath = dataItem.GetFuncCompiledPropertyPath(ClipboardContentBindingPropertyPath!);
if (_compliedClipboardValueGetter is null && !string.IsNullOrWhiteSpace(ClipboardContentBindingPropertyPath))
_compliedClipboardValueGetter = dataItem.GetCompiledValueGetter(ClipboardContentBindingPropertyPath!);

if (_funcCompiledClipboardPropertyPath is not null)
dataItem = _funcCompiledClipboardPropertyPath(dataItem);
if (_compliedClipboardValueGetter is not null)
dataItem = _compliedClipboardValueGetter(dataItem);

if (ClipboardContentBinding?.Converter is not null)
{
Expand All @@ -152,6 +154,44 @@ internal void SetOwningTableView(TableView tableView)
return dataItem;
}

/// <summary>
/// Sets the content from the clipboard to the specified data item.
/// </summary>
/// <param name="dataItem">The data item.</param>
/// <param name="value">The value to set.</param>
/// <returns><see langword="true"/> if the value was set; otherwise, <see langword="false"/>.</returns>
public virtual bool SetClipboardContent(object? dataItem, object? value)
{
if (dataItem is null)
return false;

try
{
if (_compliedClipboardValueSetter is null && !string.IsNullOrWhiteSpace(ClipboardContentBindingPropertyPath))
_compliedClipboardValueSetter = dataItem.GetCompiledValueSetter(ClipboardContentBindingPropertyPath!);

if (_compliedClipboardValueSetter is null)
return false;

if (ClipboardContentBinding?.Converter is not null)
{
value = ClipboardContentBinding.Converter.ConvertBack(
value,
typeof(object),
ClipboardContentBinding.ConverterParameter,
ClipboardContentBinding.ConverterLanguage);
}

_compliedClipboardValueSetter(dataItem, value);
return true;
}
catch (Exception ex)
{
Debug.WriteLine($"TableViewColumn: SetClipboardContent failed: {ex}");
return false;
}
}

/// <summary>
/// Gets or sets the header content of the column.
/// </summary>
Expand Down
11 changes: 11 additions & 0 deletions src/EventArgs/TableViewPasteFromClipboardEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.ComponentModel;

namespace WinUI.TableView;

/// <summary>
/// Provides data for the <see cref="TableView.PasteFromClipboard"/> event.
/// </summary>
public class TableViewPasteFromClipboardEventArgs : HandledEventArgs
{

}
Loading
Loading