0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

WinUI3 ToolTipを扱いたい

0
Posted at

WinUI3のToolTipについて学んだ事をアウトプットしていきたいと思います。

何か追加情報があれば都度記事を更新していこうと思います。

ToolTipは私が学んだ限りではあまりプロパティもなく、単純にツールチップを出力することが可能です。
各要素の属性として使用するか、子要素として使用するかの2パターンあります。

属性として使用する

各要素のToolTipService.ToolTip属性を使用します。

MainWindow.xaml
<?xml version="1.0" encoding="utf-8"?>
<Window
    x:Class="ToolTip.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:ToolTip"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Title="ToolTip">

    <StackPanel Orientation="Vertical" Margin="50">
        <TextBox Text="紫咲シオン" Background="Violet" 
                 ToolTipService.ToolTip="魔界学校の優等生" />
    </StackPanel>
</Window>

{8A1E0A2D-7532-4F38-B68B-0A73090C1CE6}.png

子要素として使用する

これは単純に先ほどの属性がタグになるだけです。

この要素を使用することにより、属性を使用するタイプよりも細かな設定が可能です。
Placementでツールチップをカーソルから見てどの位置に出力するか設定できます。
VerticalOffsetまたはHorizontalOffsetを使用することでカーソルから出力するツールチップの位置までの距離を設定できます。

MainWindow.xaml
<?xml version="1.0" encoding="utf-8"?>
<Window
    x:Class="ToolTip.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:ToolTip"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Title="ToolTip">

    <StackPanel Orientation="Vertical" Margin="50">
        <TextBox Text="紫咲シオン" Background="Violet">
            <ToolTipService.ToolTip>
                <ToolTip Content="魔界学校の優等生"
                         Placement="Left"
                         HorizontalOffset="50" />
            </ToolTipService.ToolTip>
        </TextBox>
    </StackPanel>
</Window>

image.png

また、この形式でツールチップを使用する場合、ツールチップに画像なども使用することが可能です。

MainWindow.xaml
<?xml version="1.0" encoding="utf-8"?>
<Window
    x:Class="ToolTip.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:ToolTip"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Title="ToolTip">

    <StackPanel Orientation="Vertical" Margin="50">
        <TextBox Text="紫咲シオン" Background="Violet">
            <ToolTipService.ToolTip>
                <Image Source="E:\vs\WinUI3_Test\ToolTip\ToolTip\image1.jpg" />
            </ToolTipService.ToolTip>
        </TextBox>
    </StackPanel>
</Window>

image.png

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?