[WinUI 3][InfoBar] メッセージの重要度を設定する

スポンサーリンク

この記事では InfoBar に表示するメッセージに重要度を設定する方法について説明をします。

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

重要度を設定する例

重要度を設定する例

環境

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

メッセージの重要度を設定する

メッセージの重要度を設定するには Severity プロパティに InfoBarSeverity 列挙体の値を指定します。設定する重要度によって、メッセージ表示領域の色が変わります。

説明
Error エラーを表します ピンク
Informational 情報を表します グレー
Success 成功を表します グリーン
Warning 警告を表します イエロー

XAML による例

以下は、4種類すべての InfoBar を表示する例です。

<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">

        <InfoBar 
            IsOpen="True"
            Severity="Error"
            Message="エラーメッセージです" />
        <InfoBar 
            IsOpen="True"
            Severity="Informational"
            Message="インフォメーションメッセージです" />
        <InfoBar 
            IsOpen="True"
            Severity="Success"
            Message="成功メッセージです" />
        <InfoBar 
            IsOpen="True"
            Severity="Warning"
            Message="警告メッセージです" />
        
    </StackPanel>
</Window>
重要度を設定する例

重要度を設定する例

C# の例

以下は、重要度をエラーに設定する例です。

public MainWindow()
{
    this.InitializeComponent();
    myInfoBar.Severity = Microsoft.UI.Xaml.Controls.InfoBarSeverity.Error;
}

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">

        <InfoBar
            x:Name="myInfoBar"
            IsOpen="True"
            Message="エラーメッセージです" />

    </StackPanel>
</Window>
エラーメッセージを表示する例

エラーメッセージを表示する例

WinUi Tips

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

Please follow and like us:

コメント

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