Skip to content

Commit f631795

Browse files
authored
Merge pull request #991 from Caliburn-Micro/bug/AvaloniaUI/968
Fix Avalonia UI feature conductor screen
2 parents 92a47a7 + c474e1c commit f631795

File tree

8 files changed

+19
-27
lines changed

8 files changed

+19
-27
lines changed

samples/features/Features.Avalonia/Bootstrapper.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,13 @@ public Bootstrapper()
1919

2020
Initialize();
2121

22-
Task displayTask = DisplayRootViewFor<ShellViewModel>();
23-
displayTask.Wait();
22+
InitializeAsync();
2423
}
2524

25+
private async void InitializeAsync()
26+
{
27+
await DisplayRootViewFor<ShellViewModel>();
28+
}
2629
protected override void Configure()
2730
{
2831
_container

samples/features/Features.Avalonia/Views/ConductorView.axaml

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
</StackPanel>
1919

2020

21-
<ListBox Name="Items" Grid.Row="1" Margin="40,0">
21+
<ListBox Name="Items" Grid.Row="1" Margin="40,0" SelectedItem="{Binding ActiveItem, Mode=TwoWay}">
2222
<ListBox.ItemsPanel>
2323
<ItemsPanelTemplate>
2424
<VirtualizingStackPanel Orientation="Horizontal"/>
@@ -31,16 +31,8 @@
3131
</ListBox.ItemTemplate>
3232
</ListBox>
3333

34-
<Panel DataContext="{Binding ActiveItem}" Grid.Row="2" Margin="40">
35-
<TextBlock Text="{Binding DisplayName}" FontSize="24" Foreground="Blue"/>
36-
<ItemsControl ItemsSource="{Binding Messages}" Margin="30">
37-
<ItemsControl.ItemTemplate>
38-
<DataTemplate>
39-
<TextBlock Text="{Binding}"/>
40-
</DataTemplate>
41-
</ItemsControl.ItemTemplate>
42-
</ItemsControl>
43-
</Panel>
34+
<ContentControl cal:View.Model="{Binding ActiveItem}" Grid.Row="2" Margin="40">
35+
</ContentControl>
4436

4537
</Grid>
4638
</UserControl>

samples/features/Features.Avalonia/Views/TabView.axaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
55
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
66
x:Class="Features.CrossPlatform.Views.TabView">
7-
<Grid>
7+
<StackPanel>
8+
<TextBlock Text="{Binding DisplayName}"></TextBlock>
89
<ItemsControl ItemsSource="{Binding Messages}">
910
<ItemsControl.ItemTemplate>
1011
<DataTemplate>
11-
<TextBlock Text="{Binding DisplayName}"/>
12+
<TextBlock Text="{Binding}"/>
1213
</DataTemplate>
1314
</ItemsControl.ItemTemplate>
1415
</ItemsControl>
15-
</Grid>
16+
</StackPanel>
1617
</UserControl>

samples/features/Features.CrossPlatform.Shared/ViewModels/ConductorViewModel.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@ public ConductorViewModel()
1313
Items.CollectionChanged += (s, e) => NotifyOfPropertyChange(() => CanCloseTab);
1414
}
1515

16-
protected override async Task OnActivateAsync(CancellationToken cancellationToken)
17-
{
18-
// Optionally perform any logic before activation here
19-
await base.OnActivateAsync(cancellationToken);
20-
}
2116
protected override async Task OnActivatedAsync(CancellationToken cancellationToken)
2217
{
2318
// Optionally perform any logic after activation here

src/Caliburn.Micro.Avalonia.Tests/ScreenExtenstionsTests.cs renamed to src/Caliburn.Micro.Avalonia.Tests/'ScreenExtensionsTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public override Task<bool> CanCloseAsync(CancellationToken cancellationToken = d
9898
return Task.FromResult(IsClosable);
9999
}
100100

101-
[Obsolete("Use OnActivateAsync instead.")]
101+
[Obsolete("Use OnActivatedAsync instead.")]
102102
protected override async Task OnActivateAsync(CancellationToken cancellationToken)
103103
{
104104
if (deactivationDelay.HasValue)
@@ -115,7 +115,7 @@ protected override async Task OnActivateAsync(CancellationToken cancellationToke
115115

116116
protected override async Task OnActivatedAsync(CancellationToken cancellationToken)
117117
{
118-
//here
118+
119119
if (deactivationDelay.HasValue)
120120
{
121121
await Task.Delay(deactivationDelay.Value, cancellationToken).ConfigureAwait(false);

src/Caliburn.Micro.Platform/ActionMessage.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,6 @@ protected override void OnAttached()
214214
if (View.ExecuteOnLoad(AssociatedObject, ElementLoaded))
215215
{
216216
#if AVALONIA
217-
//string eventName = "AttachedToLogicalTree";
218217
string eventName = "Loaded";
219218
var trigger = Interaction.GetBehaviors(AssociatedObject)
220219
.OfType<EventTrigger>()

src/Caliburn.Micro.Platform/ConventionManager.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,8 @@ static ConventionManager()
340340
#endif
341341
#if AVALONIA
342342
AddElementConvention<UserControl>(UserControl.IsVisibleProperty, "DataContext", loadedEvent);
343+
AddElementConvention<ListBox>(ListBox.ItemsSourceProperty, "DataContext", loadedEvent);
344+
AddElementConvention<Panel>(Panel.DataContextProperty, "DataContext", loadedEvent);
343345
#else
344346
AddElementConvention<UserControl>(UserControl.VisibilityProperty, "DataContext", loadedEvent);
345347
#endif

src/Caliburn.Micro.Platform/View.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,13 @@ public static bool ExecuteOnLoad(FrameworkElement element, RoutedEventHandler ha
234234
#if AVALONIA
235235
public static void ExecuteOnUnload(FrameworkElement element, EventHandler handler)
236236
{
237-
EventHandler<LogicalTreeAttachmentEventArgs> unloaded = null;
237+
EventHandler<RoutedEventArgs> unloaded = null;
238238
unloaded = (s, e) =>
239239
{
240-
element.DetachedFromLogicalTree -= unloaded;
240+
element.Unloaded -= unloaded;
241241
handler(s, e);
242242
};
243-
element.DetachedFromLogicalTree += unloaded;
243+
element.Unloaded += unloaded;
244244
}
245245
#else
246246
public static void ExecuteOnUnload(FrameworkElement element, RoutedEventHandler handler)

0 commit comments

Comments
 (0)