Merged MainWindowViewModel changes

This commit is contained in:
Tracy Pearson
2022-08-27 11:59:50 -04:00
2 changed files with 17 additions and 8 deletions

View File

@@ -9,10 +9,11 @@
mc:Ignorable="d"
d:DataContext="{d:DesignInstance Type={x:Type local:MainWindowViewModel}}"
Title="MainWindow" Height="450" Width="800">
<Grid Background="DarkRed">
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<ContentControl Grid.Row="0"
Visibility="Visible"
@@ -26,7 +27,9 @@
</DataTemplate>
</ContentControl.Resources>
</ContentControl>
<Button Grid.Row="1"
<ListView Grid.Row="1"
ItemsSource="{Binding Strings}"/>
<Button Grid.Row="2"
HorizontalAlignment="Center"
Command="{Binding StartCommand}"
Content="Start"/>

View File

@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Input;
using System.Windows.Threading;
@@ -29,17 +31,18 @@ namespace WpfViewModelFirst
}
private void Part1Action()
{
var currentDispatcher = Dispatcher.CurrentDispatcher;
CurrentViewModel = null;
Task delay = Task.Run(LongDelay).ContinueWith(c =>
LongDelay().ContinueWith(c =>
{
System.Diagnostics.Debug.WriteLine(c.Result);
CurrentViewModel = _viewModelFactory.GetPart2ViewModel();
currentDispatcher.Invoke(() =>
{
Strings.Add($"{DateTime.Now}");
}
);
}, TaskContinuationOptions.OnlyOnRanToCompletion);
//Task.Run(async () => await LongDelay()).ContinueWith(c =>
// {
// System.Diagnostics.Debug.WriteLine(c.Result);
//CurrentViewModel = new Part2ViewModel();
//}, TaskContinuationOptions.OnlyOnRanToCompletion);
}
private async Task<string> LongDelay()
@@ -51,5 +54,8 @@ namespace WpfViewModelFirst
private ViewModelBase? _mainFrameViewModel;
public ViewModelBase? CurrentViewModel { get => _mainFrameViewModel; set => SetProperty(ref _mainFrameViewModel, value); }
private ObservableCollection<string> _strings = new();
public ObservableCollection<string> Strings { get => _strings; set => SetProperty(ref _strings, value); }
}
}