This commit is contained in:
Igor Gritsenko 2022-01-21 23:35:29 +03:00
Родитель a9ac737de5
Коммит a043bc80d1
6 изменённых файлов: 94 добавлений и 1 удалений

Просмотреть файл

@ -9,6 +9,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Avalonia.Markup.Declarative
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AvaloniaExtensionGenerator", "AvaloniaExtensionGenerator\AvaloniaExtensionGenerator.csproj", "{5183B326-2752-4CA5-A233-D9F5B83324DF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AvaloniaMarkupSample", "Samples\AvaloniaMarkupSample\AvaloniaMarkupSample.csproj", "{612D87E7-CF30-4E08-A7C3-AF4482924EBC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -27,6 +29,10 @@ Global
{5183B326-2752-4CA5-A233-D9F5B83324DF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5183B326-2752-4CA5-A233-D9F5B83324DF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5183B326-2752-4CA5-A233-D9F5B83324DF}.Release|Any CPU.Build.0 = Release|Any CPU
{612D87E7-CF30-4E08-A7C3-AF4482924EBC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{612D87E7-CF30-4E08-A7C3-AF4482924EBC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{612D87E7-CF30-4E08-A7C3-AF4482924EBC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{612D87E7-CF30-4E08-A7C3-AF4482924EBC}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

Просмотреть файл

@ -69,7 +69,7 @@ public static partial class ControlExtensions
BindingMode? bindingMode = null,
IValueConverter converter = null,
[CallerArgumentExpression("value")] string ps = null)
where TElement : StyledElement
where TElement : StyledElement where TDataContext : class
{
dataContext = value;
return control._setEx(StyledElement.DataContextProperty, ps, () => control.DataContext = value, bindingMode, converter, null);

Просмотреть файл

@ -0,0 +1,26 @@
AppBuilder.Configure<Application>()
.UsePlatformDetect()
.UseFluentTheme()
.StartWithClassicDesktopLifetime(desktop =>
{
var count = 0;
desktop.MainWindow =
new Window().Ref(out var wnd).Content(
new StackPanel().Children(
new Button().Ref(out var button)
.Content("Welcome to Avalonia, please click me!"),
new TextBox().Ref(out var tb1)
.Text("Minimal Declarative Avalonia"),
new TextBox()
.Text(@wnd.Title, BindingMode.TwoWay, bindingSource: wnd),
new Label().Content(
button.OnClick().Select(_ => count++).Select(x => $"You clicked {x} times.").ToBinding())
))
.Title(tb1.GetObservable(TextBox.TextProperty).Select(x => x.ToUpper()).ToBinding());
}, args);

Просмотреть файл

@ -0,0 +1,24 @@
public static class AppBuilderMinimalExtensions
{
public static TAppBuilder UseFluentTheme<TAppBuilder>(this TAppBuilder builder, FluentThemeMode mode = FluentThemeMode.Light)
where TAppBuilder : AppBuilderBase<TAppBuilder>, new()
{
return builder.AfterSetup(_ =>
builder.Instance.Styles.Add(new FluentTheme(new Uri($"avares://{System.Reflection.Assembly.GetExecutingAssembly().GetName()}")) { Mode = mode }));
}
public static int StartWithClassicDesktopLifetime<T>(this T builder, Action<IClassicDesktopStyleApplicationLifetime> callback, string[]? args, ShutdownMode shutdownMode = ShutdownMode.OnLastWindowClose) where T : AppBuilderBase<T>, new()
{
var classicDesktopStyleApplicationLifetime = new ClassicDesktopStyleApplicationLifetime
{
Args = args,
ShutdownMode = shutdownMode
};
builder.SetupWithLifetime(classicDesktopStyleApplicationLifetime);
callback?.Invoke(classicDesktopStyleApplicationLifetime);
return classicDesktopStyleApplicationLifetime.Start(args);
}
}

Просмотреть файл

@ -0,0 +1,30 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Avalonia.Desktop" Version="0.10.11" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Avalonia.Markup.Declarative\Avalonia.Markup.Declarative.csproj" />
</ItemGroup>
<ItemGroup>
<Using Include="System" />
<Using Include="System.Reactive.Linq" />
<Using Include="Avalonia" />
<Using Include="Avalonia.Controls" />
<Using Include="Avalonia.Controls.ApplicationLifetimes" />
<Using Include="Avalonia.Data" />
<Using Include="Avalonia.Interactivity" />
<Using Include="Avalonia.Themes.Fluent" />
<Using Include="Avalonia.Markup.Declarative" />
</ItemGroup>
</Project>

Просмотреть файл

@ -0,0 +1,7 @@
public static class EventsExtensions
{
public static IObservable<RoutedEventArgs> OnClick(this Button button)
{
return Observable.FromEventPattern<EventHandler<RoutedEventArgs>, RoutedEventArgs>(h => button.Click += h, h => button.Click -= h).Select(x => x.EventArgs);
}
}