feat: add tooltip. arrow is not supported as there is not indicator of placement on tooltip control itself.

This commit is contained in:
rabbitism 2023-01-24 15:00:35 +08:00
parent f7e61c62d1
commit 134c8a0878
7 changed files with 172 additions and 0 deletions

View File

@ -0,0 +1,93 @@
<UserControl
x:Class="Semi.Avalonia.Demo.Pages.ToolTipDemo"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
d:DesignHeight="450"
d:DesignWidth="800"
mc:Ignorable="d">
<StackPanel HorizontalAlignment="Left">
<Border
Margin="5"
Padding="50,10"
Background="Yellow"
ToolTip.Tip="This is a ToolTip">
<TextBlock>Hover Here</TextBlock>
</Border>
<ToggleSwitch
Margin="5"
Content="ToolTip Open"
IsChecked="{Binding ElementName=Border, Path=(ToolTip.IsOpen)}" />
<Border
Name="Border"
Margin="5"
Padding="50,10"
Background="Yellow"
ToolTip.Placement="Bottom">
<ToolTip.Tip>
<StackPanel>
<TextBlock Classes="h1">ToolTip</TextBlock>
<TextBlock Classes="h2">A control which pops up a hint when a control is hovered</TextBlock>
</StackPanel>
</ToolTip.Tip>
<TextBlock>ToolTip bottom placement</TextBlock>
</Border>
<Border
Margin="5"
Padding="50,10"
Background="Yellow"
ToolTip.Placement="Top"
ToolTip.Tip="Hello">
<Border.Styles>
<Style Selector="Border">
<Style.Animations>
<Animation IterationCount="Infinite" Duration="0:0:2">
<KeyFrame KeyTime="0:0:0">
<Setter Property="ToolTip.HorizontalOffset" Value="0" />
<Setter Property="ToolTip.VerticalOffset" Value="-50" />
</KeyFrame>
<KeyFrame KeyTime="0:0:2">
<Setter Property="ToolTip.HorizontalOffset" Value="100" />
<Setter Property="ToolTip.VerticalOffset" Value="50" />
</KeyFrame>
</Animation>
</Style.Animations>
</Style>
</Border.Styles>
<TextBlock>Moving offset</TextBlock>
</Border>
<Border
Margin="5"
Padding="50,10"
Background="Yellow"
ToolTip.Placement="Top"
ToolTip.Tip="Hello">
<TextBlock>Top</TextBlock>
</Border>
<Border
Margin="5"
Padding="50,10"
Background="Yellow"
ToolTip.Placement="Left"
ToolTip.Tip="Hello">
<TextBlock>Left</TextBlock>
</Border>
<Border
Margin="5"
Padding="50,10"
Background="Yellow"
ToolTip.Placement="Right"
ToolTip.Tip="Hello">
<TextBlock>Right</TextBlock>
</Border>
<Border
Margin="5"
Padding="50,10"
Background="Yellow"
ToolTip.Placement="Bottom"
ToolTip.Tip="Hello">
<TextBlock>Bottom</TextBlock>
</Border>
</StackPanel>
</UserControl>

View File

@ -0,0 +1,18 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
namespace Semi.Avalonia.Demo.Pages;
public partial class ToolTipDemo : UserControl
{
public ToolTipDemo()
{
InitializeComponent();
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
}

View File

@ -78,6 +78,9 @@
<TabItem Header="ToggleSwitch"> <TabItem Header="ToggleSwitch">
<pages:ToggleSwitchDemo /> <pages:ToggleSwitchDemo />
</TabItem> </TabItem>
<TabItem Header="ToolTip">
<pages:ToolTipDemo />
</TabItem>
<TabItem Header="TreeView"> <TabItem Header="TreeView">
<pages:TreeViewDemo /> <pages:TreeViewDemo />
</TabItem> </TabItem>

View File

@ -31,6 +31,7 @@
<ResourceInclude Source="avares://Semi.Avalonia/Controls/TextBox.axaml" /> <ResourceInclude Source="avares://Semi.Avalonia/Controls/TextBox.axaml" />
<ResourceInclude Source="avares://Semi.Avalonia/Controls/ToggleButton.axaml" /> <ResourceInclude Source="avares://Semi.Avalonia/Controls/ToggleButton.axaml" />
<ResourceInclude Source="avares://Semi.Avalonia/Controls/ToggleSwitch.axaml" /> <ResourceInclude Source="avares://Semi.Avalonia/Controls/ToggleSwitch.axaml" />
<ResourceInclude Source="avares://Semi.Avalonia/Controls/Tooltip.axaml" />
<ResourceInclude Source="avares://Semi.Avalonia/Controls/TreeView.axaml" /> <ResourceInclude Source="avares://Semi.Avalonia/Controls/TreeView.axaml" />
<ResourceInclude Source="avares://Semi.Avalonia/Controls/UserControl.axaml" /> <ResourceInclude Source="avares://Semi.Avalonia/Controls/UserControl.axaml" />
<ResourceInclude Source="avares://Semi.Avalonia/Controls/Window.axaml" /> <ResourceInclude Source="avares://Semi.Avalonia/Controls/Window.axaml" />

View File

@ -0,0 +1,41 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<!-- Add Resources Here -->
<ControlTheme x:Key="{x:Type ToolTip}" TargetType="ToolTip">
<Setter Property="Foreground" Value="{DynamicResource ToolTipForeground}" />
<Setter Property="Background" Value="{DynamicResource ToolTipBackground}" />
<Setter Property="BorderBrush" Value="{DynamicResource ToolTipBorderBrush}" />
<Setter Property="BorderThickness" Value="{DynamicResource ToolTipBorderThickness}" />
<Setter Property="Padding" Value="{DynamicResource ToolTipPadding}" />
<Setter Property="MaxWidth" Value="{DynamicResource ToolTipMaxWidth}" />
<Setter Property="CornerRadius" Value="{DynamicResource ToolTipCornerRadius}" />
<Setter Property="Opacity" Value="0" />
<Setter Property="Transitions">
<Transitions>
<DoubleTransition Property="Opacity" Duration="0:0:0.1" />
</Transitions>
</Setter>
<Setter Property="Template">
<ControlTemplate TargetType="ToolTip">
<Border
Name="PART_LayoutRoot"
Margin="0,-1,0,0"
Padding="{TemplateBinding Padding}"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding CornerRadius}">
<ContentPresenter
Name="PART_ContentPresenter"
MaxWidth="{TemplateBinding MaxWidth}"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"
TextBlock.TextWrapping="Wrap" />
</Border>
</ControlTemplate>
</Setter>
<Style Selector="^:open">
<Setter Property="Opacity" Value="1" />
</Style>
</ControlTheme>
</ResourceDictionary>

View File

@ -23,8 +23,10 @@
<ResourceInclude Source="avares://Semi.Avalonia/Themes/Light/TextBox.axaml" /> <ResourceInclude Source="avares://Semi.Avalonia/Themes/Light/TextBox.axaml" />
<ResourceInclude Source="avares://Semi.Avalonia/Themes/Light/ToggleButton.axaml" /> <ResourceInclude Source="avares://Semi.Avalonia/Themes/Light/ToggleButton.axaml" />
<ResourceInclude Source="avares://Semi.Avalonia/Themes/Light/ToggleSwitch.axaml" /> <ResourceInclude Source="avares://Semi.Avalonia/Themes/Light/ToggleSwitch.axaml" />
<ResourceInclude Source="avares://Semi.Avalonia/Themes/Light/Tooltip.axaml" />
<ResourceInclude Source="avares://Semi.Avalonia/Themes/Light/TreeView.axaml" /> <ResourceInclude Source="avares://Semi.Avalonia/Themes/Light/TreeView.axaml" />
<ResourceInclude Source="avares://Semi.Avalonia/Themes/Light/Window.axaml" /> <ResourceInclude Source="avares://Semi.Avalonia/Themes/Light/Window.axaml" />
<ResourceInclude Source="avares://Semi.Avalonia/Themes/Light/Flyout.axaml" /> <ResourceInclude Source="avares://Semi.Avalonia/Themes/Light/Flyout.axaml" />
</ResourceDictionary.MergedDictionaries> </ResourceDictionary.MergedDictionaries>
</ResourceDictionary> </ResourceDictionary>

View File

@ -0,0 +1,14 @@
<ResourceDictionary
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=System.Runtime">
<!-- Add Resources Here -->
<PathGeometry x:Key="ToolTipTriangleGlyph">M24 0V1C20 1 18.5 2 16.5 4C14.5 6 14 7 12 7C10 7 9.5 6 7.5 4C5.5 2 4 1 0 1V0H24Z</PathGeometry>
<SolidColorBrush x:Key="ToolTipBackground" Color="#41464C" />
<SolidColorBrush x:Key="ToolTipForeground" Color="White" />
<SolidColorBrush x:Key="ToolTipBorderBrush" Color="Transparent" />
<CornerRadius x:Key="ToolTipCornerRadius">6</CornerRadius>
<Thickness x:Key="ToolTipPadding">12 8</Thickness>
<sys:Double x:Key="ToolTipMaxWidth">320</sys:Double>
<Thickness x:Key="ToolTipBorderThickness">0</Thickness>
</ResourceDictionary>