Skip to content

Commit

Permalink
新增 情景方法参数Enum类型支持手动选择
Browse files Browse the repository at this point in the history
  • Loading branch information
MakesYT committed Jul 12, 2024
1 parent 64ab806 commit 4426143
Show file tree
Hide file tree
Showing 12 changed files with 701 additions and 323 deletions.
9 changes: 5 additions & 4 deletions Core/Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<AvaloniaVersion>11.2.999-cibuild0050044-alpha</AvaloniaVersion>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
Expand All @@ -30,12 +31,12 @@
</ItemGroup>-->

<ItemGroup>
<PackageReference Include="Avalonia" Version="11.1.0-rc2"/>
<PackageReference Include="Avalonia.Desktop" Version="11.1.0-rc2"/>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)"/>
<PackageReference Include="Avalonia.Desktop" Version="$(AvaloniaVersion)"/>
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.1.0-rc2"/>
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="$(AvaloniaVersion)"/>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2"/>
<PackageReference Include="FluentAvaloniaUI" Version="2.0.5" />
<PackageReference Include="FluentAvaloniaUI" Version="2.1.0-preview4"/>
<PackageReference Include="log4net" Version="2.0.17"/>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.1"/>
<PackageReference Include="SharpHook" Version="5.3.7"/>
Expand Down
83 changes: 38 additions & 45 deletions KitopiaAvalonia/Controls/HotKeyShowItme.axaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Styles xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:KitopiaAvalonia.Controls"
xmlns:controls1="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia">
xmlns:controls="using:KitopiaAvalonia.Controls">
<Design.PreviewWith>
<controls:HotKeyShowItme Content="Ctrl" />
</Design.PreviewWith>
Expand All @@ -10,57 +9,51 @@
<!-- Set Defaults -->
<Setter Property="Template">
<ControlTemplate>
<controls1:FABorder Background="{DynamicResource AccentButtonBackground}"
BorderBrush="{DynamicResource AccentButtonBorderBrush}"
BorderThickness="{DynamicResource ButtonBorderThemeThickness}"
CornerRadius="{DynamicResource ControlCornerRadius}"
Name="Root">
<controls1:FABorder.Styles>
<Style Selector="controls1|FABorder:disabled">
<Setter Property="Background" Value="{DynamicResource AccentButtonBackgroundDisabled}" />
</Style>
</controls1:FABorder.Styles>
<Border
x:Name="ContentBorder"
<Border Name="Root"
Background="{DynamicResource AccentButtonBackground}"
BorderBrush="{DynamicResource AccentButtonBorderBrush}"
BorderThickness="{DynamicResource ButtonBorderThemeThickness}"
CornerRadius="{DynamicResource ControlCornerRadius}"
Width="{TemplateBinding Width}"
Height="{TemplateBinding Height}"
MinWidth="{TemplateBinding MinWidth}"
MinHeight="{TemplateBinding MinHeight}"
Padding="{StaticResource ButtonPadding}"
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
VerticalAlignment="{TemplateBinding VerticalAlignment}"
CornerRadius="{TemplateBinding Border.CornerRadius}">

<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
VerticalAlignment="{TemplateBinding VerticalAlignment}">

<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>

<ContentPresenter
x:Name="ControlIcon"
Grid.Column="0"
VerticalAlignment="Center"
Content="{TemplateBinding Icon}"
Foreground="{DynamicResource AccentButtonForeground}"
Focusable="False">

<ContentPresenter
x:Name="ControlIcon"
Grid.Column="0"
VerticalAlignment="Center"
Content="{TemplateBinding Icon}"
Foreground="{DynamicResource AccentButtonForeground}"
Focusable="False">

</ContentPresenter>
</ContentPresenter>

<ContentPresenter
x:Name="ContentPresenter"
Grid.Column="1"
VerticalAlignment="Center"
Content="{TemplateBinding Content}"
Foreground="{DynamicResource AccentButtonForeground}">

</ContentPresenter>
</Grid>
<Border.Styles>
<Style Selector="Border:disabled">
<Setter Property="Background" Value="{DynamicResource AccentButtonBackgroundDisabled}" />
</Style>
</Border.Styles>
</Border>

<ContentPresenter
x:Name="ContentPresenter"
Grid.Column="1"
VerticalAlignment="Center"
Content="{TemplateBinding Content}"
Foreground="{DynamicResource AccentButtonForeground}">

</ContentPresenter>
</Grid>

</Border>
</controls1:FABorder>


</ControlTemplate>
</Setter>
</Style>
Expand Down
2 changes: 1 addition & 1 deletion KitopiaAvalonia/Controls/ListShow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<Button.Styles>

<Style
Selector="Button#Button:pointerover /template/ controls1|FABorder#Root">
Selector="Button#Button:pointerover /template/ Border#Root">

<Setter Property="Background">
<SolidColorBrush
Expand Down
10 changes: 5 additions & 5 deletions KitopiaAvalonia/KitopiaAvalonia.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
<DebugType Condition="'$(Configuration)' == 'Release'">none</DebugType>
<Version>0.0.2.053</Version>
<AvaloniaVersion>11.1.0-beta2</AvaloniaVersion>
<AvaloniaVersion>11.2.999-cibuild0050044-alpha</AvaloniaVersion>
</PropertyGroup>


Expand All @@ -52,14 +52,14 @@

<ItemGroup>
<PackageReference Condition="$(DefineConstants.Contains(ENABLE_XAML_HOT_RELOAD))" Include="Avalonia.Markup.Xaml.Loader" Version="$(AvaloniaVersion)" />
<PackageReference Include="Avalonia.ReactiveUI" Version="11.1.0-rc2"/>
<PackageReference Include="Avalonia.ReactiveUI" Version="$(AvaloniaVersion)"/>
<PackageReference Condition="$(DefineConstants.Contains(ENABLE_XAML_HOT_RELOAD))" Include="HotAvalonia" Version="1.1.1"/>
<PackageReference Include="HotAvalonia.Extensions" Version="1.1.1" PrivateAssets="All"/>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" Version="11.1.0-rc2"/>
<PackageReference Include="Avalonia.Desktop" Version="11.1.0-rc2"/>
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.1.0-rc2"/>
<PackageReference Include="Avalonia" Version="$(AvaloniaVersion)"/>
<PackageReference Include="Avalonia.Desktop" Version="$(AvaloniaVersion)"/>
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="$(AvaloniaVersion)"/>
<PackageReference Include="Avalonia.Xaml.Behaviors" Version="11.1.0-rc2"/>
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2"/>
<PackageReference Include="log4net" Version="2.0.17"/>
Expand Down
47 changes: 16 additions & 31 deletions KitopiaAvalonia/Pages/MyDataTemplateSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,11 @@

using System;
using System.Collections.Generic;
using System.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Templates;
using Avalonia.Data;
using Avalonia.Layout;
using Avalonia.Media;
using Avalonia.Metadata;
using Core.SDKs.CustomScenario;
using KitopiaAvalonia.Tools;

#endregion

Expand All @@ -21,6 +17,15 @@ public class MyDataTemplateSelector : IDataTemplate
// Override the SelectTemplate method
[Content] public Dictionary<string, IDataTemplate> Templates { get; } = new Dictionary<string, IDataTemplate>();

private static Type ResolveType(string? ns, string typeName)
{
return typeName switch
{
"TextBlock" => typeof(TextBlock),
"ComboBox" => typeof(ComboBox),
_ => throw new InvalidOperationException($"Could not resolve type {typeName}.")
};
}

public Control? Build(object? item)
{
Expand All @@ -41,34 +46,14 @@ public class MyDataTemplateSelector : IDataTemplate
return control;
}


if (pointItem.RealType.BaseType.FullName == "System.Enum")
{
StackPanel stackPanel = new StackPanel();
stackPanel.Orientation = Orientation.Horizontal;
stackPanel.VerticalAlignment = VerticalAlignment.Center;
stackPanel.HorizontalAlignment = HorizontalAlignment.Right;
TextBlock textBlock = new TextBlock
{
VerticalAlignment = VerticalAlignment.Center,
Name = "textBlock",
Foreground = Application.Current.Resources["TextFillColorPrimaryBrush"] as IBrush,
};
var binding = new Binding();
binding.Path = "Title";
textBlock.Bind(TextBlock.TextProperty, binding);
stackPanel.Children.Add(textBlock);
var itemsSource = pointItem.RealType.GetEnumValues();
var enumerable = itemsSource.Cast<Object>().ToList().AsReadOnly();
var comboBox = new ComboBox()
{
ItemsSource = enumerable,
SelectedIndex = 0
};
var bingding2 = new Binding();
bingding2.Path = "InputObject";
comboBox.Bind(ComboBox.SelectedValueProperty, bingding2);
stackPanel.Children.Add(comboBox);
return stackPanel;
var control = Templates["EnumTemplate"].Build(item);
var childOfType = control.GetChildOfType<ComboBox>("ComboBox");
childOfType.ItemsSource = pointItem.RealType.GetEnumValues();
Console.WriteLine(1);
return control;
}

switch (pointItem.RealType.FullName!)
Expand Down
1 change: 1 addition & 0 deletions KitopiaAvalonia/Services/ScreenCaptureWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public async Task<ScreenCaptureInfo> GetScreenCaptureInfo()
CanResize = false,
IsVisible = true,
};

window.MosaicImage.Source = captureAllScreen.Item2.Count > 0 ? captureAllScreen.Item2.Dequeue() : null;
window.Image.Source = captureAllScreen.Item1.Count > 0 ? captureAllScreen.Item1.Dequeue() : null;
window.SetToSelectMode(action);
Expand Down
Loading

0 comments on commit 4426143

Please sign in to comment.