mirror of
https://gitcode.com/gh_mirrors/se/Semi.Avalonia
synced 2026-04-07 09:46:36 +08:00
feat: add CopyText to HighContrastDemo.
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
xmlns:vm="clr-namespace:Semi.Avalonia.Demo.ViewModels"
|
xmlns:vm="clr-namespace:Semi.Avalonia.Demo.ViewModels"
|
||||||
xmlns:controls="clr-namespace:Semi.Avalonia.Demo.Controls"
|
xmlns:controls="clr-namespace:Semi.Avalonia.Demo.Controls"
|
||||||
xmlns:cvt="clr-namespace:Semi.Avalonia.Demo.Converters"
|
xmlns:cvt="clr-namespace:Semi.Avalonia.Demo.Converters"
|
||||||
|
xmlns:pages="clr-namespace:Semi.Avalonia.Demo.Pages"
|
||||||
mc:Ignorable="d" d:DesignWidth="1000" d:DesignHeight="1450"
|
mc:Ignorable="d" d:DesignWidth="1000" d:DesignHeight="1450"
|
||||||
x:DataType="vm:HighContrastDemoViewModel"
|
x:DataType="vm:HighContrastDemoViewModel"
|
||||||
x:CompileBindings="True"
|
x:CompileBindings="True"
|
||||||
@@ -306,6 +307,27 @@
|
|||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</DataGridTemplateColumn.CellTemplate>
|
</DataGridTemplateColumn.CellTemplate>
|
||||||
</DataGridTemplateColumn>
|
</DataGridTemplateColumn>
|
||||||
|
|
||||||
|
<DataGridTemplateColumn Width="100" Header="CopyText">
|
||||||
|
<DataGridTemplateColumn.CellTemplate>
|
||||||
|
<DataTemplate DataType="vm:ColorResource">
|
||||||
|
<StackPanel Orientation="Horizontal">
|
||||||
|
<Button
|
||||||
|
Command="{Binding $parent[pages:HighContrastDemo].Copy}"
|
||||||
|
CommandParameter="{Binding CopyText1}"
|
||||||
|
Theme="{DynamicResource IconBorderlessButton}"
|
||||||
|
Content="{StaticResource SemiIconCopy}"
|
||||||
|
ToolTip.Tip="StaticResource" />
|
||||||
|
<Button
|
||||||
|
Command="{Binding $parent[pages:HighContrastDemo].Copy}"
|
||||||
|
CommandParameter="{Binding CopyText2}"
|
||||||
|
Theme="{DynamicResource IconBorderlessButton}"
|
||||||
|
Content="{StaticResource SemiIconCopy}"
|
||||||
|
ToolTip.Tip="DynamicResource" />
|
||||||
|
</StackPanel>
|
||||||
|
</DataTemplate>
|
||||||
|
</DataGridTemplateColumn.CellTemplate>
|
||||||
|
</DataGridTemplateColumn>
|
||||||
</DataGrid.Columns>
|
</DataGrid.Columns>
|
||||||
</DataGrid>
|
</DataGrid>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Avalonia.Controls;
|
using System.Threading.Tasks;
|
||||||
|
using Avalonia.Controls;
|
||||||
using Semi.Avalonia.Demo.ViewModels;
|
using Semi.Avalonia.Demo.ViewModels;
|
||||||
|
|
||||||
namespace Semi.Avalonia.Demo.Pages;
|
namespace Semi.Avalonia.Demo.Pages;
|
||||||
@@ -10,4 +11,14 @@ public partial class HighContrastDemo : UserControl
|
|||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
this.DataContext = new HighContrastDemoViewModel();
|
this.DataContext = new HighContrastDemoViewModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task Copy(object? o)
|
||||||
|
{
|
||||||
|
if (o is null) return;
|
||||||
|
var toplevel = TopLevel.GetTopLevel(this);
|
||||||
|
if (toplevel?.Clipboard is { } c)
|
||||||
|
{
|
||||||
|
await c.SetTextAsync(o.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -31,35 +31,35 @@ public partial class HighContrastDemoViewModel : ObservableObject
|
|||||||
[
|
[
|
||||||
new ColorResource
|
new ColorResource
|
||||||
{
|
{
|
||||||
ResourceKey = "WindowColor",
|
ResourceKey = "SemiColorWindow",
|
||||||
Brush = new SolidColorBrush(Color.Parse("#202020")),
|
Brush = new SolidColorBrush(Color.Parse("#202020")),
|
||||||
Description = "Background of pages, panes, popups, and windows.",
|
Description = "Background of pages, panes, popups, and windows.",
|
||||||
PairWith = "WindowTextColor"
|
PairWith = "WindowTextColor"
|
||||||
},
|
},
|
||||||
new ColorResource
|
new ColorResource
|
||||||
{
|
{
|
||||||
ResourceKey = "WindowTextColor",
|
ResourceKey = "SemiColorWindowText",
|
||||||
Brush = new SolidColorBrush(Color.Parse("#FFFFFF")),
|
Brush = new SolidColorBrush(Color.Parse("#FFFFFF")),
|
||||||
Description = "Headings, body copy, lists, placeholder text, app and window borders.",
|
Description = "Headings, body copy, lists, placeholder text, app and window borders.",
|
||||||
PairWith = "WindowColor"
|
PairWith = "WindowColor"
|
||||||
},
|
},
|
||||||
new ColorResource
|
new ColorResource
|
||||||
{
|
{
|
||||||
ResourceKey = "HotlightColor",
|
ResourceKey = "SemiColorHotlight",
|
||||||
Brush = new SolidColorBrush(Color.Parse("#75E9FC")),
|
Brush = new SolidColorBrush(Color.Parse("#75E9FC")),
|
||||||
Description = "Hyperlinks.",
|
Description = "Hyperlinks.",
|
||||||
PairWith = "WindowColor"
|
PairWith = "WindowColor"
|
||||||
},
|
},
|
||||||
new ColorResource
|
new ColorResource
|
||||||
{
|
{
|
||||||
ResourceKey = "GrayTextColor",
|
ResourceKey = "SemiColorGrayText",
|
||||||
Brush = new SolidColorBrush(Color.Parse("#A6A6A6")),
|
Brush = new SolidColorBrush(Color.Parse("#A6A6A6")),
|
||||||
Description = "Inactive (disabled) UI.",
|
Description = "Inactive (disabled) UI.",
|
||||||
PairWith = "WindowColor"
|
PairWith = "WindowColor"
|
||||||
},
|
},
|
||||||
new ColorResource
|
new ColorResource
|
||||||
{
|
{
|
||||||
ResourceKey = "HighlightTextColor",
|
ResourceKey = "SemiColorHighlightText",
|
||||||
Brush = new SolidColorBrush(Color.Parse("#263B50")),
|
Brush = new SolidColorBrush(Color.Parse("#263B50")),
|
||||||
Description =
|
Description =
|
||||||
"Foreground color for text or UI that is in selected, interacted with (hover, pressed), or in progress.",
|
"Foreground color for text or UI that is in selected, interacted with (hover, pressed), or in progress.",
|
||||||
@@ -67,7 +67,7 @@ public partial class HighContrastDemoViewModel : ObservableObject
|
|||||||
},
|
},
|
||||||
new ColorResource
|
new ColorResource
|
||||||
{
|
{
|
||||||
ResourceKey = "HighlightColor",
|
ResourceKey = "SemiColorHighlight",
|
||||||
Brush = new SolidColorBrush(Color.Parse("#8EE3F0")),
|
Brush = new SolidColorBrush(Color.Parse("#8EE3F0")),
|
||||||
Description =
|
Description =
|
||||||
"Background or accent color for UI that is in selected, interacted with (hover, pressed), or in progress.",
|
"Background or accent color for UI that is in selected, interacted with (hover, pressed), or in progress.",
|
||||||
@@ -75,14 +75,14 @@ public partial class HighContrastDemoViewModel : ObservableObject
|
|||||||
},
|
},
|
||||||
new ColorResource
|
new ColorResource
|
||||||
{
|
{
|
||||||
ResourceKey = "ButtonTextColor",
|
ResourceKey = "SemiColorButtonText",
|
||||||
Brush = new SolidColorBrush(Color.Parse("#FFFFFF")),
|
Brush = new SolidColorBrush(Color.Parse("#FFFFFF")),
|
||||||
Description = "Foreground color for buttons and any UI that can be interacted with.",
|
Description = "Foreground color for buttons and any UI that can be interacted with.",
|
||||||
PairWith = "ButtonFaceColor"
|
PairWith = "ButtonFaceColor"
|
||||||
},
|
},
|
||||||
new ColorResource
|
new ColorResource
|
||||||
{
|
{
|
||||||
ResourceKey = "ButtonFaceColor",
|
ResourceKey = "SemiColorButtonFace",
|
||||||
Brush = new SolidColorBrush(Color.Parse("#202020")),
|
Brush = new SolidColorBrush(Color.Parse("#202020")),
|
||||||
Description = "Background color for buttons and any UI that can be interacted with.",
|
Description = "Background color for buttons and any UI that can be interacted with.",
|
||||||
PairWith = "ButtonTextColor"
|
PairWith = "ButtonTextColor"
|
||||||
@@ -100,9 +100,10 @@ public partial class HighContrastDemoViewModel : ObservableObject
|
|||||||
foreach (var colorResource in ColorResources)
|
foreach (var colorResource in ColorResources)
|
||||||
{
|
{
|
||||||
if (colorResource.ResourceKey is null) continue;
|
if (colorResource.ResourceKey is null) continue;
|
||||||
if (topLevel?.TryFindResource(colorResource.ResourceKey, value, out var o) == true && o is Color color)
|
if (topLevel?.TryFindResource(colorResource.ResourceKey, value, out var o) == true
|
||||||
|
&& o is ISolidColorBrush color)
|
||||||
{
|
{
|
||||||
colorResource.Brush = new SolidColorBrush(color);
|
colorResource.Brush = color;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -121,7 +122,17 @@ public partial class HighContrastDemoViewModel : ObservableObject
|
|||||||
public partial class ColorResource : ObservableObject
|
public partial class ColorResource : ObservableObject
|
||||||
{
|
{
|
||||||
[ObservableProperty] private string? _resourceKey;
|
[ObservableProperty] private string? _resourceKey;
|
||||||
[ObservableProperty] private SolidColorBrush? _brush;
|
[ObservableProperty] private ISolidColorBrush? _brush;
|
||||||
[ObservableProperty] private string? _description;
|
[ObservableProperty] private string? _description;
|
||||||
[ObservableProperty] private string? _pairWith;
|
[ObservableProperty] private string? _pairWith;
|
||||||
|
|
||||||
|
public string CopyText1 =>
|
||||||
|
$"""
|
||||||
|
<StaticResource x:Key="" ResourceKey="{ResourceKey}" />
|
||||||
|
""";
|
||||||
|
|
||||||
|
public string CopyText2 =>
|
||||||
|
$"""
|
||||||
|
<DynamicResource x:Key="" ResourceKey="{ResourceKey}" />
|
||||||
|
""";
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user