enhance: Optimized the ScrollViewer style.
This commit is contained in:
1 parent
17c2b8473b
commit
51f07648ee
16 files changed
+458
-235
No files matched your search
@@ -1,7 +1,7 @@
|
||||
[
|
||||
{
|
||||
"title": "Styles",
|
||||
"selectedIndex": -1,
|
||||
"selectedIndex": 0,
|
||||
"group": false,
|
||||
"demoItemList": [
|
||||
[ "Brush", "BrushDemoCtl", "Brush.Brush", "", "" ],
|
||||
|
||||
@@ -65,6 +65,10 @@
|
||||
<DependentUpon>BorderDemoCtl.axaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Update="UserControl\Styles\RepeatButtonDemoCtl.axaml.cs">
|
||||
<DependentUpon>RepeatButtonDemoCtl.axaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -16,22 +16,21 @@ public class DataService
|
||||
{
|
||||
var infoList = new List<DemoInfoModel>();
|
||||
string jsonStr = ReadEmbeddedJsonFile("HandyControlDemo.Data.DemoInfo.json");
|
||||
var jsonObj = JsonConvert.DeserializeObject<dynamic>(jsonStr);
|
||||
dynamic? jsonObj = JsonConvert.DeserializeObject<dynamic>(jsonStr);
|
||||
if (jsonObj is null)
|
||||
{
|
||||
return new List<DemoInfoModel>();
|
||||
return [];
|
||||
}
|
||||
|
||||
foreach (var item in jsonObj)
|
||||
foreach (dynamic? item in jsonObj)
|
||||
{
|
||||
var titleKey = (string) item.title;
|
||||
var title = titleKey;
|
||||
string? titleKey = (string) item.title;
|
||||
List<DemoItemModel> list = Convert2DemoItemList(item.demoItemList);
|
||||
|
||||
var demoInfoModel = new DemoInfoModel
|
||||
{
|
||||
Key = titleKey,
|
||||
Title = title,
|
||||
Title = titleKey,
|
||||
DemoItemList = list,
|
||||
SelectedIndex = (int) item.selectedIndex,
|
||||
IsGroupEnabled = (bool) item.group
|
||||
@@ -43,10 +42,10 @@ public class DataService
|
||||
return infoList;
|
||||
}
|
||||
|
||||
private string ReadEmbeddedJsonFile(string resourceName)
|
||||
private static string ReadEmbeddedJsonFile(string resourceName)
|
||||
{
|
||||
var assembly = Assembly.GetExecutingAssembly();
|
||||
var resourceNameWithNamespace = assembly.GetManifestResourceNames()
|
||||
string? resourceNameWithNamespace = assembly.GetManifestResourceNames()
|
||||
.FirstOrDefault(n => n.EndsWith(resourceName, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
if (resourceNameWithNamespace is null)
|
||||
@@ -64,17 +63,17 @@ public class DataService
|
||||
return reader.ReadToEnd();
|
||||
}
|
||||
|
||||
private List<DemoItemModel> Convert2DemoItemList(dynamic list)
|
||||
private static List<DemoItemModel> Convert2DemoItemList(dynamic list)
|
||||
{
|
||||
var resultList = new List<DemoItemModel>();
|
||||
|
||||
foreach (var item in list)
|
||||
foreach (dynamic? item in list)
|
||||
{
|
||||
var name = (string) item[0];
|
||||
string? name = (string) item[0];
|
||||
string targetCtlName = item[1];
|
||||
string imageBrushName = item[2];
|
||||
var isNew = !string.IsNullOrEmpty((string) item[3]);
|
||||
var groupName = (string) item[4];
|
||||
bool isNew = !string.IsNullOrEmpty((string) item[3]);
|
||||
string? groupName = (string) item[4];
|
||||
if (string.IsNullOrEmpty(groupName))
|
||||
{
|
||||
groupName = "Misc";
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
x:Class="HandyControlDemo.UserControl.RepeatButtonDemoCtl"
|
||||
xmlns:hc="https://handyorg.github.io/handycontrol"
|
||||
Background="{DynamicResource RegionBrush}">
|
||||
<ScrollViewer>
|
||||
<hc:UniformSpacingPanel ChildWrapping="Wrap"
|
||||
Spacing="32"
|
||||
Margin="32">
|
||||
<hc:UniformSpacingPanel Orientation="Vertical"
|
||||
Spacing="32">
|
||||
<WrapPanel>
|
||||
<StackPanel>
|
||||
<RepeatButton Content="default"
|
||||
Margin="5" />
|
||||
<RepeatButton IsEnabled="False"
|
||||
Content="default"
|
||||
Margin="5" />
|
||||
</StackPanel>
|
||||
<StackPanel>
|
||||
<RepeatButton Content="primary"
|
||||
Margin="5"
|
||||
Theme="{StaticResource RepeatButtonPrimary}" />
|
||||
<RepeatButton IsEnabled="False"
|
||||
Content="primary"
|
||||
Margin="5"
|
||||
Theme="{StaticResource RepeatButtonPrimary}" />
|
||||
</StackPanel>
|
||||
<StackPanel>
|
||||
<RepeatButton Content="success"
|
||||
Margin="5"
|
||||
Theme="{StaticResource RepeatButtonSuccess}" />
|
||||
<RepeatButton IsEnabled="False"
|
||||
Content="success"
|
||||
Margin="5"
|
||||
Theme="{StaticResource RepeatButtonSuccess}" />
|
||||
</StackPanel>
|
||||
<StackPanel>
|
||||
<RepeatButton Content="info"
|
||||
Margin="5"
|
||||
Theme="{StaticResource RepeatButtonInfo}" />
|
||||
<RepeatButton IsEnabled="False"
|
||||
Content="info"
|
||||
Margin="5"
|
||||
Theme="{StaticResource RepeatButtonInfo}" />
|
||||
</StackPanel>
|
||||
<StackPanel>
|
||||
<RepeatButton Content="warning"
|
||||
Margin="5"
|
||||
Theme="{StaticResource RepeatButtonWarning}" />
|
||||
<RepeatButton IsEnabled="False"
|
||||
Content="warning"
|
||||
Margin="5"
|
||||
Theme="{StaticResource RepeatButtonWarning}" />
|
||||
</StackPanel>
|
||||
<StackPanel>
|
||||
<RepeatButton Content="danger"
|
||||
Margin="5"
|
||||
Theme="{StaticResource RepeatButtonDanger}" />
|
||||
<RepeatButton IsEnabled="False"
|
||||
Content="danger"
|
||||
Margin="5"
|
||||
Theme="{StaticResource RepeatButtonDanger}" />
|
||||
</StackPanel>
|
||||
</WrapPanel>
|
||||
</hc:UniformSpacingPanel>
|
||||
</hc:UniformSpacingPanel>
|
||||
</ScrollViewer>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace HandyControlDemo.UserControl;
|
||||
|
||||
public partial class RepeatButtonDemoCtl : Avalonia.Controls.UserControl
|
||||
{
|
||||
public RepeatButtonDemoCtl()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using Avalonia.Threading;
|
||||
using CommunityToolkit.Mvvm.Messaging;
|
||||
using HandyControlDemo.Data;
|
||||
@@ -44,10 +45,11 @@ public class MainViewModel : DemoViewModelBase<DemoDataModel>
|
||||
|
||||
private void UpdateMainContent()
|
||||
{
|
||||
WeakReferenceMessenger.Default.Register<DemoItemModel, string>(this, MessageToken.SwitchDemo, (_, message) =>
|
||||
{
|
||||
SwitchDemo(message);
|
||||
});
|
||||
WeakReferenceMessenger.Default.Register<DemoItemModel, string>(
|
||||
recipient: this,
|
||||
token: MessageToken.SwitchDemo,
|
||||
handler: (_, message) => SwitchDemo(message)
|
||||
);
|
||||
}
|
||||
|
||||
private void UpdateLeftContent()
|
||||
@@ -76,11 +78,9 @@ public class MainViewModel : DemoViewModelBase<DemoDataModel>
|
||||
DemoInfoCollection = [];
|
||||
foreach (var item in _dataService.GetDemoInfo())
|
||||
{
|
||||
Dispatcher.UIThread.InvokeAsync(() =>
|
||||
{
|
||||
DemoInfoCollection.Add(item);
|
||||
}, DispatcherPriority.ApplicationIdle);
|
||||
Dispatcher.UIThread.InvokeAsync(() => DemoInfoCollection.Add(item));
|
||||
}
|
||||
Dispatcher.UIThread.InvokeAsync(() => SwitchDemo(DemoInfoCollection.First().DemoItemList.First()));
|
||||
}
|
||||
|
||||
private void SwitchDemo(DemoItemModel item)
|
||||
@@ -92,7 +92,8 @@ public class MainViewModel : DemoViewModelBase<DemoDataModel>
|
||||
|
||||
DemoItemCurrent = item;
|
||||
ContentTitle = Lang.ResourceManager.GetString(item.Name, Lang.Culture);
|
||||
object? demoControl = AssemblyHelper.ResolveByKey(item.TargetCtlName) ?? AssemblyHelper.CreateInternalInstance($"UserControl.{item.TargetCtlName}");
|
||||
object? demoControl = AssemblyHelper.ResolveByKey(item.TargetCtlName) ??
|
||||
AssemblyHelper.CreateInternalInstance($"UserControl.{item.TargetCtlName}");
|
||||
SubContent = demoControl;
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,8 @@ namespace HandyControlDemo.ViewModel;
|
||||
|
||||
public class ViewModelLocator
|
||||
{
|
||||
private static readonly Lazy<ViewModelLocator> InstanceInternal = new(() => new ViewModelLocator(), isThreadSafe: true);
|
||||
private static readonly Lazy<ViewModelLocator> InstanceInternal =
|
||||
new(() => new ViewModelLocator(), isThreadSafe: true);
|
||||
|
||||
public static ViewModelLocator Instance => InstanceInternal.Value;
|
||||
|
||||
|
||||
Reference in new issue
Block a user