Wpf-tooltip
提供:Dev Guides
WPF-ツールチップ
ツールチップは、GUIの要素の情報を表示するポップアップウィンドウを作成するコントロールです。 ToolTipクラスの階層的な継承は次のとおりです-
ToolTipクラスの一般的に使用されるプロパティ
以下に、ToolTipの最も一般的に使用されるプロパティを示します。
Sr. No. | Property & Description |
---|---|
1 |
IsOpen ToolTipが表示されるかどうかを示す値を取得または設定します。 |
2 |
IsOpenProperty IsOpen依存プロパティを識別します。 |
3 |
Placement 配置ターゲット要素に対するツールチップの配置方法を取得または設定します。 |
4 |
PlacementProperty Placement依存プロパティを識別します。 |
5 |
PlacementTarget ToolTipServiceによって開かれたときにツールチップを配置する視覚要素またはコントロールを取得または設定します。 |
6 |
PlacementTargetProperty PlacementTarget依存プロパティを識別します。 |
7 |
TemplateSettings ToolTipのテンプレートを定義するときにTemplateBindingソースとして参照できる計算値を提供するオブジェクトを取得します。 |
ToolTipクラスの一般的に使用されるイベント
以下に、ToolTipの最も一般的に使用されるイベントを示します。
Sr. No. | Events & Description |
---|---|
1 |
Closed ツールヒントが閉じられ、表示されなくなったときに発生します。 |
2 |
Opened ToolTipが表示されると発生します。 |
例
- WPFToolTipControl という名前の新しいWPFプロジェクトを作成しましょう。
- ツールボックスから2つのテキストブロック、2つのテキストボックス、1つのボタンをドラッグします。
- 次の例は、WPFアプリケーションでツールヒントを使用する方法を示しています。
- 次のXAMLコードは、ボタンとテキストボックスにツールヒントを表示するためのいくつかのプロパティを持つツールヒントを作成します。
<Window x:Class = "WPFToolTipControl.MainWindow"
xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
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"
xmlns:local = "clr-namespace:WPFToolTipControl"
mc:Ignorable = "d" Title = "MainWindow" Height = "350" Width = "604">
<Grid>
<TextBlock x:Name = "textBlock" HorizontalAlignment = "Left"
Margin = "101,75,0,0" TextWrapping = "Wrap"
Text = "User Name" VerticalAlignment = "Top"/>
<TextBlock x:Name = "textBlock1" HorizontalAlignment = "Left"
Margin = "101,125,0,0" TextWrapping = "Wrap"
Text = "Password" VerticalAlignment = "Top"/>
<TextBox x:Name = "textBox" HorizontalAlignment = "Left"
Height = "24" Margin = "199,75,0,0" TextWrapping = "Wrap"
VerticalAlignment = "Top" Width = "219"
ToolTipService.ToolTip = "Enter User Name"/>
<PasswordBox x:Name = "passwordBox" HorizontalAlignment = "Left"
Margin = "199,125,0,0" VerticalAlignment = "Top" Width = "219"
Height = "24" ToolTipService.ToolTip = "Enter Password"/>
<Button x:Name = "button" Content = "Log in" HorizontalAlignment = "Left"
Margin = "199,189,0,0" VerticalAlignment = "Top" Width = "75"
ToolTipService.ToolTip = "Log in"/>
</Grid>
</Window>
上記のコードをコンパイルして実行すると、次の出力が生成されます。 マウスがボタンまたはテキストボックスの領域に入ると、ツールヒントが表示されます。
上記のサンプルコードを実行し、ToolTipクラスの他のプロパティとイベントを試すことをお勧めします。