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" Grid.Row="0"
Content="Launch" Content="Launch"
Command="{Binding LaunchCommand}" Command="{Binding LaunchCommand}"
Background="Green"
HorizontalAlignment="Left" HorizontalAlignment="Left"
VerticalAlignment="Stretch" VerticalAlignment="Stretch"
Margin="10,10,0,0"/> Margin="10,10,0,0"/>
@ -50,15 +51,17 @@
</ComboBox.ItemTemplate> </ComboBox.ItemTemplate>
</ComboBox> </ComboBox>
</Grid> </Grid>
<ScrollViewer Grid.Row="1" x:Name="OutputScrollViewer">
<TextBlock Grid.Row="1" <TextBlock ScrollViewer.HorizontalScrollBarVisibility="Hidden"
Name="OutputBlock" ScrollViewer.VerticalScrollBarVisibility="Auto"
Margin="10,10,10,10" Name="OutputBlock"
Text="{Binding ConsoleOutput, Mode=OneWay}" Margin="10,10,10,10"
FontFamily="Consolas" Text="{Binding ConsoleOutput, Mode=OneWay}"
TextWrapping="Wrap" FontFamily="Consolas"
Background="{DynamicResource ControlFillColorDisabledBrush}" TextWrapping="Wrap"
HorizontalAlignment="Stretch" Background="{DynamicResource ControlFillColorDisabledBrush}"
VerticalAlignment="Stretch"/> HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"/>
</ScrollViewer>
</Grid> </Grid>
</Page> </Page>

12
StabilityMatrix/LaunchPage.xaml.cs

@ -1,4 +1,5 @@
using System.Windows; using System;
using System.Windows;
using System.Windows.Controls; using System.Windows.Controls;
using StabilityMatrix.ViewModels; using StabilityMatrix.ViewModels;
@ -19,5 +20,14 @@ public sealed partial class LaunchPage : Page
{ {
viewModel.OnLoaded(); viewModel.OnLoaded();
SelectPackageComboBox.ItemsSource = viewModel.InstalledPackages; 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 ObservableCollection<InstalledPackage> InstalledPackages = new();
public event EventHandler ScrollNeeded;
public LaunchViewModel(ISettingsManager settingsManager) public LaunchViewModel(ISettingsManager settingsManager)
{ {
@ -52,12 +53,14 @@ public partial class LaunchViewModel : ObservableObject
{ {
// Clear console // Clear console
ConsoleOutput = ""; ConsoleOutput = "";
if (SelectedPackage == null) if (SelectedPackage == null)
{ {
ConsoleOutput = "No package selected"; ConsoleOutput = "No package selected";
return; return;
} }
await PyRunner.Initialize();
// Get path from package // Get path from package
var packagePath = SelectedPackage.Path; var packagePath = SelectedPackage.Path;
@ -77,6 +80,7 @@ public partial class LaunchViewModel : ObservableObject
{ {
Debug.WriteLine($"process stdout: {s}"); Debug.WriteLine($"process stdout: {s}");
ConsoleOutput += s + "\n"; 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}"); Debug.WriteLine($"Venv process exited with code {i}");
ConsoleOutput += $"Venv process exited with code {i}"; ConsoleOutput += $"Venv process exited with code {i}";
ScrollNeeded?.Invoke(this, EventArgs.Empty);
}); });
}); });

Loading…
Cancel
Save