[WinUI 3][TextBox] テキストの水平方向の配置を設定する

スポンサーリンク

この記事では TextBox に ヘッダー を表示する方法について説明をします。

公式サイト情報はコチラを参照してください。

環境

開発環境 Microsoft Visual Studio Enterprise 2019
Version 16.11.5
Framework Microsoft .NET Framewohttps://blog.hiros-dot.net/?p=11007rk Version 4.8.04161

テキストの水平方向の配置位置を設定する

TextBox のテキストは、左寄せ、中央寄せ、右寄せなど、水平方向の配置位置を設定することができます。

水平方向の配置は TextAlignment プロパティで設定することができ、その値は以下に示す TextAlignment 列挙体で指定します。

説明
Left 左寄せ(既定値)
Center 中央寄せ
Right 右寄せ
Justify 均等割

以下は「右寄せ」に設定する例です。

XAML の例

<Window
    x:Class="WinUISample.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:WinUISample"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <StackPanel Orientation="Vertical" HorizontalAlignment="Center">

        <TextBox x:Name="myTextBox"
                 TextAlignment="Right"
                 Width="300"/>
    </StackPanel>
</Window>

C# の例

public MainWindow()
{
    this.InitializeComponent();

    myTextBox.TextAlignment = TextAlignment.Right;
}
テキストを右寄せにする例

テキストを右寄せにする例

WinUi Tips

本サイトでまとめている WinUI Tips の一覧はこちらから確認できます。

Please follow and like us:

コメント

タイトルとURLをコピーしました