Skip to content

Commit

Permalink
Remove Class1, update project files, and enhance MainViewModel
Browse files Browse the repository at this point in the history
Removed Class1.cs and ClassLibrary1.csproj, including references to MVVMFluent. Updated MVVMFluent.NugetDemo.csproj to remove commented-out reference and update MVVMFluent.WPF package version. Enhanced MainViewModel with a new constructor, modified Input property setter, improved exception handling, and added CancellationToken support in ShowDialogAsync. Made minor formatting changes in MainWindow.xaml. Updated MVVMFluent.WPF.csproj to use Version property.
  • Loading branch information
ktuatcowi committed Oct 2, 2024
1 parent 9deee57 commit 3c616ab
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 55 deletions.
9 changes: 0 additions & 9 deletions src/ClassLibrary1/Class1.cs

This file was deleted.

16 changes: 0 additions & 16 deletions src/ClassLibrary1/ClassLibrary1.csproj

This file was deleted.

6 changes: 1 addition & 5 deletions src/MVVMFluent.NugetDemo/MVVMFluent.NugetDemo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@
</PropertyGroup>

<ItemGroup>
<!--<PackageReference Include="MVVMFluent" Version="0.0.1-alfa21">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>-->
<PackageReference Include="MVVMFluent.WPF" Version="0.0.1-alfa22">
<PackageReference Include="MVVMFluent.WPF" Version="0.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
20 changes: 14 additions & 6 deletions src/MVVMFluent.NugetDemo/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@ namespace MVVMFluent.NugetDemo;

internal class MainViewModel : ValidationViewModelBase
{
public MainViewModel()
{
Input = "Hello World";
}

public bool Enable { get => Get(true); set => Set(value); }

public string? Input
{
get => Get<string?>();
set => When(value).Required().Notify(OkCommand, AsyncCommand).Set();
set => When(value).Required().Notify(AsyncCommand, OkCommand).Set();
}

public Command OkCommand => Do(() => ShowDialog(Input)).IfValid(nameof(Input));
Expand All @@ -26,17 +31,20 @@ private bool CanExecute()

private void HandleException(Exception exception)
{
MessageBox.Show(exception.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
if (exception is TaskCanceledException)
MessageBox.Show(exception.Message, "Information", MessageBoxButton.OK, MessageBoxImage.Information);
else
MessageBox.Show(exception.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}

private async Task ShowDialogAsync()
private async Task ShowDialogAsync(CancellationToken cancellationToken)
{
for (var i = 1; i <= 100; i++)
{
if (AsyncCommand.IsCancellationRequested)
return;
if (cancellationToken.IsCancellationRequested)
throw new TaskCanceledException();

await Task.Delay(50);
await Task.Delay(50, cancellationToken);
AsyncCommand.ReportProgress(i + 1, 100);

if (AsyncCommand.Progress == 50 && ThrowException)
Expand Down
36 changes: 18 additions & 18 deletions src/MVVMFluent.NugetDemo/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
</Grid.RowDefinitions>

<Button HorizontalAlignment="Right" Padding="15,0" Margin="10"
Content="Help"
Command="{Binding HelpCommand}" CommandParameter="This is the help" />
Content="Help"
Command="{Binding HelpCommand}" CommandParameter="This is the help" />

<TextBox Grid.Row="1" VerticalAlignment="Center" Padding="10" Margin="10"
Text="{Binding Input, UpdateSourceTrigger=PropertyChanged,
ValidatesOnNotifyDataErrors=True}"
IsEnabled="{Binding Enable}">
Text="{Binding Input, UpdateSourceTrigger=PropertyChanged,
ValidatesOnNotifyDataErrors=True}"
IsEnabled="{Binding Enable}">
<Validation.ErrorTemplate>
<ControlTemplate>
<StackPanel>
Expand All @@ -40,7 +40,7 @@
</TextBox>

<ProgressBar Grid.Row="2" VerticalAlignment="Center" Padding="10" Margin="10"
Value="{Binding AsyncCommand.Progress}" Minimum="0" Maximum="100" Height="10">
Value="{Binding AsyncCommand.Progress}" Minimum="0" Maximum="100" Height="10">
<ProgressBar.Style>
<Style TargetType="ProgressBar">
<Style.Triggers>
Expand All @@ -54,26 +54,26 @@

<DockPanel Grid.Row="3" HorizontalAlignment="Stretch" LastChildFill="True">
<Button DockPanel.Dock="Right" Padding="15,0" Margin="10"
Content="Ok" IsDefault="True"
Command="{Binding OkCommand}" />
Content="Ok" IsDefault="True"
Command="{Binding OkCommand}" />

<Button DockPanel.Dock="Right" Padding="15,0" Margin="10"
Content="Async"
Command="{Binding AsyncCommand}" />
Content="Async"
Command="{Binding AsyncCommand}" />

<Button DockPanel.Dock="Right" Padding="15,0" Margin="10"
Content="Cancel"
Command="{Binding AsyncCommand.CancelCommand}" />
Content="Cancel"
Command="{Binding AsyncCommand.CancelCommand}" />

<CheckBox DockPanel.Dock="Left" Padding="10" Margin="10,5"
VerticalAlignment="Center" VerticalContentAlignment="Center"
Content="Enable"
IsChecked="{Binding Enable}" />
VerticalAlignment="Center" VerticalContentAlignment="Center"
Content="Enable"
IsChecked="{Binding Enable}" />

<CheckBox DockPanel.Dock="Left" Padding="10" Margin="10,5"
VerticalAlignment="Center" VerticalContentAlignment="Center"
Content="Throw Exception"
IsChecked="{Binding ThrowException}" />
VerticalAlignment="Center" VerticalContentAlignment="Center"
Content="Throw Exception"
IsChecked="{Binding ThrowException}" />
</DockPanel>

</Grid>
Expand Down
2 changes: 1 addition & 1 deletion src/MVVMFluent.WPF/MVVMFluent.WPF.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Nullable>enable</Nullable>
<UseWPF>true</UseWPF>
<NuSpecFile>MVVMFluent.WPF.nuspec</NuSpecFile>
<VersionPrefix>0.0.1</VersionPrefix>
<Version>0.0.1</Version>
<NuspecProperties>version=$(Version)</NuspecProperties>
</PropertyGroup>

Expand Down

0 comments on commit 3c616ab

Please sign in to comment.