Browse Source

Add scroll bar to OutputBlock

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

23
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,15 +51,17 @@
</ComboBox.ItemTemplate>
</ComboBox>
</Grid>
<TextBlock Grid.Row="1"
Name="OutputBlock"
Margin="10,10,10,10"
Text="{Binding ConsoleOutput, Mode=OneWay}"
FontFamily="Consolas"
TextWrapping="Wrap"
Background="{DynamicResource ControlFillColorDisabledBrush}"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"/>
<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}"
FontFamily="Consolas"
TextWrapping="Wrap"
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();
});
}
}

7
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)
{
@ -52,12 +53,14 @@ public partial class LaunchViewModel : ObservableObject
{
// Clear console
ConsoleOutput = "";
if (SelectedPackage == null)
{
ConsoleOutput = "No package selected";
return;
}
await PyRunner.Initialize();
// Get path from package
var packagePath = SelectedPackage.Path;
@ -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