ステータスバーはウィンドウ下部にメッセージを表示できるコントロールです。
ファイル名:NoXAML22Statusbar.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UseWPF>true</UseWPF>
</PropertyGroup>
</Project>
ファイル名:App.cs
using System;
using System.Windows;
namespace NoXAML22Statusbar;
public class App : Application
{
[STAThread]
public static void Main(string[] args)
{
var app = new App();
app.Run();
}
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
var win = new MainWindow();
win.Show();
}
}
ファイル名:AssemblyInfo.cs
using System.Windows;
[assembly:ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
ファイル名:MainWindow.cs
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
namespace NoXAML22Statusbar;
public class MainWindow : Window
{
public MainWindow()
{
this.Title = "NoXAML StatusBar Sample";
this.Width = 400;
this.Height = 300;
// メインのレイアウト
var dock = new DockPanel();
// ステータスバー作成
var statusBar = new StatusBar();
statusBar.Items.Add(new TextBlock { Text = "準備完了" });
// 下部に貼り付け
DockPanel.SetDock(statusBar, Dock.Bottom);
dock.Children.Add(statusBar);
// メインコンテンツ(例としてTextBox)
var mainContent = new TextBox { Text = "ここに本文", AcceptsReturn = true };
dock.Children.Add(mainContent);
this.Content = dock;
}
}
コメント