Skip to content

Commit 4121ef0

Browse files
committed
Refactor UI layout and data context management
- Replaced `Panel` with `ContentControl` in `ConductorView.axaml` for better layout handling. - Changed root element from `Grid` to `StackPanel` in `TabView.axaml`, and updated data binding for `ItemsControl`. - Added `DataContext` binding convention for `Panel` in `ConventionManager.cs` to enhance data context management.
1 parent 03f399b commit 4121ef0

File tree

3 files changed

+7
-13
lines changed

3 files changed

+7
-13
lines changed

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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>

src/Caliburn.Micro.Platform/ConventionManager.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ static ConventionManager()
341341
#if AVALONIA
342342
AddElementConvention<UserControl>(UserControl.IsVisibleProperty, "DataContext", loadedEvent);
343343
AddElementConvention<ListBox>(ListBox.ItemsSourceProperty, "DataContext", loadedEvent);
344+
AddElementConvention<Panel>(Panel.DataContextProperty, "DataContext", loadedEvent);
344345
#else
345346
AddElementConvention<UserControl>(UserControl.VisibilityProperty, "DataContext", loadedEvent);
346347
#endif

0 commit comments

Comments
 (0)