タブコントロールはWebブラウザなどで複数のページを切り替えて表示する為のコントロールです。
ファイル名:NoXAML24Tab.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 NoXAML24Tab;
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;
namespace NoXAML24Tab;
public class MainWindow : Window
{
public MainWindow()
{
Title = "NoXAML TabControl Sample";
Width = 400;
Height = 300;
// TabControl本体
var tabControl = new TabControl();
// Tab 1
var tab1 = new TabItem { Header = "Tab 1" };
tab1.Content = new TextBlock { Text = "This is Tab 1.", Margin = new Thickness(20) };
// Tab 2
var tab2 = new TabItem { Header = "Tab 2" };
tab2.Content = new TextBlock { Text = "This is Tab 2.", Margin = new Thickness(20) };
// 追加
tabControl.Items.Add(tab1);
tabControl.Items.Add(tab2);
// ウィンドウに配置
Content = tabControl;
}
}
コメント