Implemented export to CSV functionality.
This commit is contained in:
1 parent
a478d4ebb0
commit
ddbc745200
4 files changed
+98
-9
No files matched your search
@@ -65,16 +65,16 @@
|
||||
DockPanel.Dock="Left">
|
||||
<Button Grid.Column="0" Margin="5" Width="100" HorizontalContentAlignment="Center" Content="Delete"
|
||||
Command="{Binding DeleteCommand}" />
|
||||
<Button Grid.Column="1" Margin="5" Width="100" HorizontalContentAlignment="Center"
|
||||
Content="Find..."
|
||||
Command="{Binding FindCommand}" />
|
||||
<!-- <Button Grid.Column="1" Margin="5" Width="100" HorizontalContentAlignment="Center" -->
|
||||
<!-- Content="Find..." -->
|
||||
<!-- Command="{Binding FindCommand}" /> -->
|
||||
</Grid>
|
||||
<Grid HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="5" ColumnDefinitions="Auto, Auto"
|
||||
DockPanel.Dock="Right">
|
||||
<Label Grid.Column="0" Margin="5" VerticalAlignment="Center"
|
||||
Content="{Binding TotalValue, StringFormat='Total Value: ${0:0.00}'}" />
|
||||
<Button Grid.Column="1" Margin="5" Width="150" HorizontalContentAlignment="Center"
|
||||
Content="Export to CSV..." />
|
||||
Content="Export to CSV..." Command="{Binding ExportCommand}" />
|
||||
</Grid>
|
||||
</DockPanel>
|
||||
</Grid>
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reactive;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia.Platform.Storage;
|
||||
using Avalonia.ReactiveUI;
|
||||
using PcgsInvUi.ViewModels;
|
||||
using ReactiveUI;
|
||||
@@ -10,7 +13,8 @@ public partial class MainWindow : ReactiveWindow<MainWindowViewModel> {
|
||||
public MainWindow() {
|
||||
InitializeComponent();
|
||||
this.WhenActivated(d => d(ViewModel!.ShowDeleteWindow.RegisterHandler(ShowDeleteWindowAsync)));
|
||||
this.WhenActivated(d => d(ViewModel!.ShowFindWindow.RegisterHandler(ShowFindWindowAsync)));
|
||||
this.WhenActivated(d => d(ViewModel!.ShowExportWindow.RegisterHandler(ShowFilePickerAsync)));
|
||||
// this.WhenActivated(d => d(ViewModel!.ShowFindWindow.RegisterHandler(ShowFindWindowAsync)));
|
||||
}
|
||||
|
||||
public async Task ShowDeleteWindowAsync(InteractionContext<DeleteWindowViewModel, Boolean> interaction) {
|
||||
@@ -28,4 +32,22 @@ public partial class MainWindow : ReactiveWindow<MainWindowViewModel> {
|
||||
var result = await window.ShowDialog<int>(this);
|
||||
interaction.SetOutput(result);
|
||||
}
|
||||
|
||||
public async Task ShowFilePickerAsync(InteractionContext<Unit, Stream> interationContext) {
|
||||
var topLevel = GetTopLevel(this);
|
||||
var file = await topLevel.StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions {
|
||||
Title = "Save CSV...",
|
||||
DefaultExtension = ".csv",
|
||||
ShowOverwritePrompt = true,
|
||||
SuggestedFileName = "coins.csv",
|
||||
SuggestedStartLocation = await StorageProvider.TryGetWellKnownFolderAsync(WellKnownFolder.Documents)
|
||||
});
|
||||
|
||||
Stream stream;
|
||||
|
||||
if (file is not null) {
|
||||
stream = await file.OpenWriteAsync();
|
||||
interationContext.SetOutput(stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user