Skip to content

Commit

Permalink
Merge pull request #160 from Insire/dev
Browse files Browse the repository at this point in the history
update from dev
  • Loading branch information
Insire authored Jul 3, 2021
2 parents 18849fe + 208ea96 commit db33c75
Show file tree
Hide file tree
Showing 32 changed files with 491 additions and 230 deletions.
19 changes: 19 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,22 @@ csharp_using_directive_placement = outside_namespace:suggestion
dotnet_sort_system_directives_first = false
dotnet_separate_import_directive_groups = false
csharp_prefer_simple_using_statement = false:suggestion

dotnet_style_prefer_simplified_boolean_expressions = true:suggestion

# IDE0058: Expression value is never used
csharp_style_unused_value_expression_statement_preference = discard_variable
dotnet_diagnostic.IDE0058.severity = none

# IDE0045: Use conditional expression for assignment
dotnet_style_prefer_conditional_expression_over_assignment = false

# CA2208: Instantiate argument exceptions correctly
dotnet_diagnostic.CA2208.severity = none

# CA1806: Do not ignore method results
dotnet_diagnostic.CA1806.severity = none

# IDE0130: Namespace does not match folder structure
dotnet_style_namespace_match_folder = true
dotnet_diagnostic.IDE0130.severity = none
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,19 @@ Pre release nuget packages are available [here](https://pkgs.dev.azure.com/SoftT
- [MvvmScarletToolkit.Xamarin.Forms](src/MvvmScarletToolkit.Xamarin.Forms/readme.md)

- BindingProxy
- (Multi-)Converters as Markupextension
- InvertBooleanConverter
- Converters:
- IsNot (negate a boolean)
- IsNotNull (return whether something is not null)
- IsNotNullOrEmpty (return whether a string is not null or empty)
- IsNotNullOrWhiteSpace (return whether a string is not null or whitespace)
- IsNull (return whether something is null)
- IsNullOrEmpty (return whether a string is null or empty)
- IsNullOrWhiteSpace (return whether a string is null or whitespace)
- MarkupExtension
- ColorToHexExtension
- Behaviors
- BehaviorBase (provides the currently associated control that also forwwards updates to the bindingcontext as it changes on the control)
- EventToCommandBehavior

- [MvvmScarletToolkit.Abstractions](src/MvvmScarletToolkit.Abstractions/readme.md)

Expand Down
7 changes: 7 additions & 0 deletions src/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,11 @@
<PropertyGroup>
<CodeAnalysisRuleSet>..\..\MvvmScarletToolkit.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>

<ItemGroup Condition=" '$(Configuration)'=='Debug' ">
<PackageReference Include="Roslynator.Analyzers" Version="3.2.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Roslynator.Analyzers" Version="3.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>

<PackageReference Include="Nerdbank.GitVersioning" Version="3.4.194">
<PackageReference Include="Nerdbank.GitVersioning" Version="3.4.220">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Toolkit.Mvvm" Version="7.0.2" />

<PackageReference Include="Roslynator.Analyzers" Version="3.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>

<PackageReference Include="Nerdbank.GitVersioning" Version="3.4.194">
<PackageReference Include="Nerdbank.GitVersioning" Version="3.4.220">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="DynamicData" Version="7.1.16" />
<PackageReference Include="DynamicData" Version="7.1.17" />
<PackageReference Include="Microsoft.Xaml.Behaviors.Wpf" Version="1.1.31" />
<PackageReference Include="System.Drawing.Common" Version="5.0.2" />

<PackageReference Include="Roslynator.Analyzers" Version="3.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

<ItemGroup>
<PackageReference Include="Microsoft.Toolkit.Mvvm" Version="7.0.2" />
<PackageReference Include="DynamicData" Version="7.1.16" />
<PackageReference Include="DynamicData" Version="7.1.17" />

<PackageReference Include="Roslynator.Analyzers" Version="3.1.0">
<PackageReference Include="Roslynator.Analyzers" Version="3.2.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>

<PackageReference Include="Nerdbank.GitVersioning" Version="3.4.194">
<PackageReference Include="Nerdbank.GitVersioning" Version="3.4.220">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
4 changes: 3 additions & 1 deletion src/MvvmScarletToolkit.Wpf.Samples/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
using Jot.Storage;
using MvvmScarletToolkit.Observables;
using System;
using System.Runtime.Versioning;
using System.Threading;
using System.Windows;

namespace MvvmScarletToolkit.Wpf.Samples
{
[SupportedOSPlatform("windows7.0")]
public partial class App : Application
{
private readonly Tracker _tracker;
Expand Down Expand Up @@ -37,7 +39,7 @@ protected override async void OnExit(ExitEventArgs e)
{
base.OnExit(e);

await ScarletExitService.Default.ShutDown();
await ScarletExitService.Default.ShutDown().ConfigureAwait(false);

_tracker.PersistAll();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFrameworks>net5.0-windows</TargetFrameworks>
Expand All @@ -11,12 +11,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Roslynator.Analyzers" Version="3.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Jot" Version="2.1.8" />
<PackageReference Include="XamlFlair.WPF" Version="1.2.8" />
<PackageReference Include="XamlFlair.WPF" Version="1.2.9" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
<PackageReference Include="NSubstitute.Analyzers.CSharp" Version="1.0.14" />

<PackageReference Include="nunit" Version="3.13.2" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0">
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace MvvmScarletToolkit.Wpf
{
public class ToastService : ObservableObject, IToastService
{
private static readonly Lazy<ToastService> _default = new Lazy<ToastService>(() => new ToastService(new ToastServiceConfiguration(), SynchronizationContext.Current));
private static readonly Lazy<ToastService> _default = new Lazy<ToastService>(() => new ToastService(new ToastServiceConfiguration(), SynchronizationContext.Current!));

public static IToastService Default => _default.Value;

Expand Down
4 changes: 2 additions & 2 deletions src/MvvmScarletToolkit.Wpf/MvvmScarletToolkit.Wpf.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
<ItemGroup>
<PackageReference Include="Microsoft.Toolkit.Mvvm" Version="7.0.2" />

<PackageReference Include="Roslynator.Analyzers" Version="3.1.0">
<PackageReference Include="Roslynator.Analyzers" Version="3.2.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>

<PackageReference Include="Nerdbank.GitVersioning" Version="3.4.194">
<PackageReference Include="Nerdbank.GitVersioning" Version="3.4.220">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
23 changes: 17 additions & 6 deletions src/MvvmScarletToolkit.Xamarin.Forms.Samples/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,34 @@
<ContentPage x:Class="MvvmScarletToolkit.Xamarin.Forms.Samples.MainPage"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:mvvm="http://SoftThorn.MvvmScarletToolkit.com/winfx/xaml/shared"
xmlns:samples="clr-namespace:MvvmScarletToolkit.Xamarin.Forms.Samples"
x:DataType="samples:MainPageViewModel">

<ContentPage.Resources>
<mvvm:IsNot x:Key="IsNot" />
</ContentPage.Resources>

<ContentPage.BindingContext>
<samples:MainPageViewModel />
</ContentPage.BindingContext>

<StackLayout>
<StackLayout Margin="30"
Spacing="30">
<Label HorizontalTextAlignment="Center"
Text="{Binding Count, StringFormat='{}Amount of Times worked: {0}'}" />

<Button Padding="30,24,30,0"
Command="{Binding WorkCommand}"
<Button Command="{Binding WorkCommand}"
FontSize="16"
IsEnabled="{Binding WorkCommand.IsNotBusy}"
IsEnabled="{Binding WorkCommand.IsBusy, Converter={StaticResource IsNot}}"
Text="Work" />

<Button Padding="30,24,30,0"
Command="{Binding ResetCommand}"
<Button Command="{Binding WorkCommand.CancelCommand}"
FontSize="16"
IsEnabled="{Binding WorkCommand.IsBusy}"
Text="Cancel Work" />

<Button Command="{Binding ResetCommand}"
FontSize="16"
IsEnabled="{Binding ResetCommand.IsNotBusy}"
Text="Reset" />
Expand Down
15 changes: 10 additions & 5 deletions src/MvvmScarletToolkit.Xamarin.Forms.Samples/MainPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@ public int Count
public MainPageViewModel()
: base(ScarletCommandBuilder.Default)
{
WorkCommand = CommandBuilder.Create(Work, CanWork)
WorkCommand = CommandBuilder
.Create(Work, CanWork)
.WithSingleExecution("Work")
.WithBusyNotification(BusyStack)
.WithAsyncCancellation()
.Build();

ResetCommand = CommandBuilder.Create(Reset, CanReset)
ResetCommand = CommandBuilder
.Create(Reset, CanReset)
.WithSingleExecution("Reset")
.WithBusyNotification(BusyStack)
.Build();
Expand All @@ -35,7 +38,7 @@ public MainPageViewModel()
private async Task Reset(CancellationToken token)
{
Debug.WriteLine("Resetting ...");
await Task.Delay(2000, token);
await Task.Delay(2000, token).ConfigureAwait(false);
Debug.WriteLine("Reset complete ...");

Count = 0;
Expand All @@ -50,10 +53,12 @@ private bool CanReset()
private async Task Work(CancellationToken token)
{
Debug.WriteLine("Working ...");
await Task.Delay(2000, token);
await Task.Delay(2000, token).ConfigureAwait(false);
Debug.WriteLine("Done ...");

//Count++;
token.ThrowIfCancellationRequested();

Count++;
}

private bool CanWork()
Expand Down
48 changes: 48 additions & 0 deletions src/MvvmScarletToolkit.Xamarin.Forms/Behaviors/BehaviorBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;
using Xamarin.Forms;

namespace MvvmScarletToolkit
{
/// <summary>
/// base class providing the currently associated control that also forwwards updates to the bindingcontext as it changes on the control
/// </summary>
/// <typeparam name="T">a control</typeparam>
public abstract class BehaviorBase<T> : Behavior<T>
where T : BindableObject
{
protected T? AssociatedObject { get; private set; }

protected override void OnAttachedTo(T bindable)
{
base.OnAttachedTo(bindable);
AssociatedObject = bindable;

if (bindable.BindingContext != null)
{
BindingContext = bindable.BindingContext;
}

bindable.BindingContextChanged += OnBindingContextChanged;
}

protected override void OnDetachingFrom(T bindable)
{
base.OnDetachingFrom(bindable);

bindable.BindingContextChanged -= OnBindingContextChanged;
AssociatedObject = null;
}

private void OnBindingContextChanged(object sender, EventArgs e)
{
OnBindingContextChanged();
}

protected override void OnBindingContextChanged()
{
base.OnBindingContextChanged();

BindingContext = AssociatedObject?.BindingContext;
}
}
}
Loading

0 comments on commit db33c75

Please sign in to comment.