Browse Source

Add scroll bar to OutputBlock

pull/5/head
JT 2 years ago
parent
commit
ad7fcd5377
  1. 7
      StabilityMatrix/LaunchPage.xaml
  2. 12
      StabilityMatrix/LaunchPage.xaml.cs
  3. 5
      StabilityMatrix/ViewModels/LaunchViewModel.cs

7
StabilityMatrix/LaunchPage.xaml

@ -29,6 +29,7 @@
Grid.Row="0"
Content="Launch"
Command="{Binding LaunchCommand}"
Background="Green"
HorizontalAlignment="Left"
VerticalAlignment="Stretch"
Margin="10,10,0,0"/>
@ -50,8 +51,9 @@
</ComboBox.ItemTemplate>
</ComboBox>
</Grid>
<TextBlock Grid.Row="1"
<ScrollViewer Grid.Row="1" x:Name="OutputScrollViewer">
<TextBlock ScrollViewer.HorizontalScrollBarVisibility="Hidden"
ScrollViewer.VerticalScrollBarVisibility="Auto"
Name="OutputBlock"
Margin="10,10,10,10"
Text="{Binding ConsoleOutput, Mode=OneWay}"
@ -60,5 +62,6 @@
Background="{DynamicResource ControlFillColorDisabledBrush}"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"/>
</ScrollViewer>
</Grid>
</Page>

12
StabilityMatrix/LaunchPage.xaml.cs

@ -1,4 +1,5 @@
using System.Windows;
using System;
using System.Windows;
using System.Windows.Controls;
using StabilityMatrix.ViewModels;
@ -19,5 +20,14 @@ public sealed partial class LaunchPage : Page
{
viewModel.OnLoaded();
SelectPackageComboBox.ItemsSource = viewModel.InstalledPackages;
viewModel.ScrollNeeded += ViewModelOnScrollNeeded;
}
private void ViewModelOnScrollNeeded(object? sender, EventArgs e)
{
Dispatcher.Invoke(() =>
{
OutputScrollViewer.ScrollToBottom();
});
}
}

5
StabilityMatrix/ViewModels/LaunchViewModel.cs

@ -42,6 +42,7 @@ public partial class LaunchViewModel : ObservableObject
}
public ObservableCollection<InstalledPackage> InstalledPackages = new();
public event EventHandler ScrollNeeded;
public LaunchViewModel(ISettingsManager settingsManager)
{
@ -59,6 +60,8 @@ public partial class LaunchViewModel : ObservableObject
return;
}
await PyRunner.Initialize();
// Get path from package
var packagePath = SelectedPackage.Path;
var venvPath = Path.Combine(packagePath, "venv");
@ -77,6 +80,7 @@ public partial class LaunchViewModel : ObservableObject
{
Debug.WriteLine($"process stdout: {s}");
ConsoleOutput += s + "\n";
ScrollNeeded?.Invoke(this, EventArgs.Empty);
});
});
@ -86,6 +90,7 @@ public partial class LaunchViewModel : ObservableObject
{
Debug.WriteLine($"Venv process exited with code {i}");
ConsoleOutput += $"Venv process exited with code {i}";
ScrollNeeded?.Invoke(this, EventArgs.Empty);
});
});

Loading…
Cancel
Save