Skip to content

Commit

Permalink
Select first section automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperJMN committed Dec 22, 2023
1 parent 2f7c418 commit 421223c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/AvaloniaSyncer/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive;
using System.Reactive.Linq;
using System.Threading.Tasks;
using ReactiveUI;
using ReactiveUI.Fody.Helpers;

namespace AvaloniaSyncer.ViewModels;

Expand All @@ -14,8 +17,16 @@ public MainViewModel(Func<Task<IEnumerable<Section>>> sectionsFactory)
{
LoadSections = ReactiveCommand.CreateFromTask(sectionsFactory);
sectionsHelper = LoadSections.ToProperty(this, x => x.Sections);

this.WhenAnyValue(model => model.Sections)
.WhereNotNull()
.Do(sections => SelectedSection = sections.First())
.Subscribe();
}

[Reactive]
public Section SelectedSection { get; set; }

public IEnumerable<Section> Sections => sectionsHelper.Value;

public ReactiveCommand<Unit, IEnumerable<Section>> LoadSections { get; }
Expand Down
2 changes: 1 addition & 1 deletion src/AvaloniaSyncer/Views/MainView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<DockPanel>
<controls:MasterDetailsNavigator DockPanel.Dock="Top" />
<controls:MasterDetailsView ItemsSource="{Binding Sections}" MasterPaneWidth="120">
<controls:MasterDetailsView ItemsSource="{Binding Sections}" SelectedItem="{Binding SelectedSection}" MasterPaneWidth="120">
<controls:MasterDetailsView.ItemTemplate>
<DataTemplate x:DataType="vm:Section">
<TextBlock Text="{Binding Name}" />
Expand Down

0 comments on commit 421223c

Please sign in to comment.