-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add avalonia TabControl demo.
- Loading branch information
Showing
12 changed files
with
682 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
189 changes: 189 additions & 0 deletions
189
src/Avalonia/HandyControlDemo_Avalonia/UserControl/Styles/NativeTabControlDemo.axaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
<UserControl xmlns="https://github.com/avaloniaui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
x:Class="HandyControlDemo.UserControl.NativeTabControlDemo" | ||
xmlns:hc="https://handyorg.github.io/handycontrol"> | ||
<ScrollViewer> | ||
<hc:UniformSpacingPanel Margin="32" | ||
Spacing="32" | ||
ItemWidth="400" | ||
ItemHeight="200" | ||
MaxWidth="832" | ||
ChildWrapping="Wrap"> | ||
<TabControl TabStripPlacement="Right"> | ||
<TabItem Header="Title1"> | ||
<Border> | ||
<TextBlock Theme="{StaticResource TextBlockLargeBold}"> | ||
<Run Text="Text" /> | ||
<Run Text="1" /> | ||
</TextBlock> | ||
</Border> | ||
</TabItem> | ||
<TabItem Header="Title2" | ||
IsEnabled="False"> | ||
<Border> | ||
<TextBlock Theme="{StaticResource TextBlockLargeBold}"> | ||
<Run Text="Text" /> | ||
<Run Text="2" /> | ||
</TextBlock> | ||
</Border> | ||
</TabItem> | ||
<TabItem Header="Title3"> | ||
<Border> | ||
<TextBlock Theme="{StaticResource TextBlockLargeBold}"> | ||
<Run Text="Text" /> | ||
<Run Text="3" /> | ||
</TextBlock> | ||
</Border> | ||
</TabItem> | ||
<TabItem Header="Title4"> | ||
<Border> | ||
<TextBlock Theme="{StaticResource TextBlockLargeBold}"> | ||
<Run Text="Text" /> | ||
<Run Text="4" /> | ||
</TextBlock> | ||
</Border> | ||
</TabItem> | ||
<TabItem Header="Title5"> | ||
<Border> | ||
<TextBlock Theme="{StaticResource TextBlockLargeBold}"> | ||
<Run Text="Text" /> | ||
<Run Text="5" /> | ||
</TextBlock> | ||
</Border> | ||
</TabItem> | ||
</TabControl> | ||
<TabControl Theme="{StaticResource TabControlInLine}"> | ||
<TabItem Header="Title1"> | ||
<Border> | ||
<TextBlock Theme="{StaticResource TextBlockLargeBold}"> | ||
<Run Text="Text" /> | ||
<Run Text="1" /> | ||
</TextBlock> | ||
</Border> | ||
</TabItem> | ||
<TabItem Header="Title2"> | ||
<Border> | ||
<TextBlock Theme="{StaticResource TextBlockLargeBold}"> | ||
<Run Text="Text" /> | ||
<Run Text="2" /> | ||
</TextBlock> | ||
</Border> | ||
</TabItem> | ||
<TabItem Header="Title3"> | ||
<Border> | ||
<TextBlock Theme="{StaticResource TextBlockLargeBold}"> | ||
<Run Text="Text" /> | ||
<Run Text="3" /> | ||
</TextBlock> | ||
</Border> | ||
</TabItem> | ||
<TabItem Header="Title4"> | ||
<Border> | ||
<TextBlock Theme="{StaticResource TextBlockLargeBold}"> | ||
<Run Text="Text" /> | ||
<Run Text="4" /> | ||
</TextBlock> | ||
</Border> | ||
</TabItem> | ||
<TabItem Header="Title5" | ||
IsSelected="True"> | ||
<Border> | ||
<TextBlock Theme="{StaticResource TextBlockLargeBold}"> | ||
<Run Text="Text" /> | ||
<Run Text="5" /> | ||
</TextBlock> | ||
</Border> | ||
</TabItem> | ||
</TabControl> | ||
<TabControl TabStripPlacement="Left" | ||
Theme="{StaticResource TabControlCapsule}"> | ||
<TabItem Header="Title1"> | ||
<Border> | ||
<TextBlock Theme="{StaticResource TextBlockLargeBold}"> | ||
<Run Text="Text" /> | ||
<Run Text="1" /> | ||
</TextBlock> | ||
</Border> | ||
</TabItem> | ||
<TabItem IsSelected="True" | ||
Header="Title2"> | ||
<Border> | ||
<TextBlock Theme="{StaticResource TextBlockLargeBold}"> | ||
<Run Text="Text" /> | ||
<Run Text="2" /> | ||
</TextBlock> | ||
</Border> | ||
</TabItem> | ||
<TabItem Header="Title3"> | ||
<Border> | ||
<TextBlock Theme="{StaticResource TextBlockLargeBold}"> | ||
<Run Text="Text" /> | ||
<Run Text="3" /> | ||
</TextBlock> | ||
</Border> | ||
</TabItem> | ||
<TabItem Header="Title4"> | ||
<Border> | ||
<TextBlock Theme="{StaticResource TextBlockLargeBold}"> | ||
<Run Text="Text" /> | ||
<Run Text="4" /> | ||
</TextBlock> | ||
</Border> | ||
</TabItem> | ||
<TabItem Header="Title5"> | ||
<Border> | ||
<TextBlock Theme="{StaticResource TextBlockLargeBold}"> | ||
<Run Text="Text" /> | ||
<Run Text="5" /> | ||
</TextBlock> | ||
</Border> | ||
</TabItem> | ||
</TabControl> | ||
<TabControl TabStripPlacement="Bottom" | ||
Theme="{StaticResource TabControlCapsuleSolid}"> | ||
<TabItem Header="Title1"> | ||
<Border> | ||
<TextBlock Theme="{StaticResource TextBlockLargeBold}"> | ||
<Run Text="Text" /> | ||
<Run Text="1" /> | ||
</TextBlock> | ||
</Border> | ||
</TabItem> | ||
<TabItem IsEnabled="False" | ||
Header="Title2"> | ||
<Border> | ||
<TextBlock Theme="{StaticResource TextBlockLargeBold}"> | ||
<Run Text="Text" /> | ||
<Run Text="2" /> | ||
</TextBlock> | ||
</Border> | ||
</TabItem> | ||
<TabItem Header="Title3"> | ||
<Border> | ||
<TextBlock Theme="{StaticResource TextBlockLargeBold}"> | ||
<Run Text="Text" /> | ||
<Run Text="3" /> | ||
</TextBlock> | ||
</Border> | ||
</TabItem> | ||
<TabItem IsSelected="True" | ||
Header="Title4"> | ||
<Border> | ||
<TextBlock Theme="{StaticResource TextBlockLargeBold}"> | ||
<Run Text="Text" /> | ||
<Run Text="4" /> | ||
</TextBlock> | ||
</Border> | ||
</TabItem> | ||
<TabItem Header="Title5"> | ||
<Border> | ||
<TextBlock Theme="{StaticResource TextBlockLargeBold}"> | ||
<Run Text="Text" /> | ||
<Run Text="5" /> | ||
</TextBlock> | ||
</Border> | ||
</TabItem> | ||
</TabControl> | ||
</hc:UniformSpacingPanel> | ||
</ScrollViewer> | ||
</UserControl> |
10 changes: 10 additions & 0 deletions
10
src/Avalonia/HandyControlDemo_Avalonia/UserControl/Styles/NativeTabControlDemo.axaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
namespace HandyControlDemo.UserControl; | ||
|
||
public partial class NativeTabControlDemo : Avalonia.Controls.UserControl | ||
{ | ||
public NativeTabControlDemo() | ||
{ | ||
InitializeComponent(); | ||
} | ||
} | ||
|
71 changes: 71 additions & 0 deletions
71
src/Avalonia/HandyControl_Avalonia/Controls/Attach/ItemsControlAttach.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using Avalonia; | ||
using Avalonia.Controls; | ||
using HandyControl.Tools; | ||
|
||
namespace HandyControl.Controls; | ||
|
||
public class ItemsControlAttach | ||
{ | ||
public static readonly AttachedProperty<ThemeSelector?> ItemsContainerThemeSelectorProperty = | ||
AvaloniaProperty.RegisterAttached<ItemsControlAttach, AvaloniaObject, ThemeSelector?>( | ||
"ItemsContainerThemeSelector"); | ||
|
||
public static void SetItemsContainerThemeSelector(AvaloniaObject element, ThemeSelector? value) => | ||
element.SetValue(ItemsContainerThemeSelectorProperty, value); | ||
|
||
public static ThemeSelector? GetItemsContainerThemeSelector(AvaloniaObject element) => | ||
element.GetValue(ItemsContainerThemeSelectorProperty); | ||
|
||
static ItemsControlAttach() | ||
{ | ||
ItemsContainerThemeSelectorProperty.Changed.AddClassHandler<AvaloniaObject>( | ||
OnItemsContainerThemeSelectorChanged); | ||
} | ||
|
||
private static void OnItemsContainerThemeSelectorChanged(AvaloniaObject element, AvaloniaPropertyChangedEventArgs e) | ||
{ | ||
if (element is not ItemsControl itemsControl) | ||
{ | ||
return; | ||
} | ||
|
||
itemsControl.ContainerPrepared -= OnContainerPrepared; | ||
var themeSelector = e.GetNewValue<ThemeSelector?>(); | ||
|
||
if (themeSelector is null) | ||
{ | ||
return; | ||
} | ||
|
||
itemsControl.ContainerPrepared += OnContainerPrepared; | ||
ApplyTheme(itemsControl, themeSelector); | ||
} | ||
|
||
private static void OnContainerPrepared(object? sender, ContainerPreparedEventArgs e) | ||
{ | ||
if (sender is not ItemsControl itemsControl) | ||
{ | ||
return; | ||
} | ||
|
||
var themeSelector = GetItemsContainerThemeSelector(itemsControl); | ||
if (themeSelector is null) | ||
{ | ||
return; | ||
} | ||
|
||
ApplyTheme(itemsControl, themeSelector); | ||
} | ||
|
||
private static void ApplyTheme(ItemsControl itemsControl, ThemeSelector themeSelector) | ||
{ | ||
for (int i = 0; i < itemsControl.ItemCount; i++) | ||
{ | ||
var container = itemsControl.ContainerFromIndex(i); | ||
if (container != null) | ||
{ | ||
container.Theme = themeSelector.SelectTheme(itemsControl.Items[i], container); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.