ToggleButton は押されている状態と押されていない状態に分かれます。この記事では、ToggleButton の押下状態を設定する方法について説明します。
環境
| 開発環境 | Microsoft Visual Studio Professional 2019 Preview Version 16.11.0 Preview 3.0 |
| Framework | Microsoft .NET Framework Version 4.8.04084 |
| その他 | Microsoft.Project Reunion 0.8.0-preview |
| Microsoft.ProjectReunion.Foundation 0.8.0-preview | |
| Microsoft.ProjectReunion.WinUI 0.8.0-preview | |
| Microsoft.UI.Xaml 2.6.1 |
ToggleButton の押下状態を設定する
ToggleButton の押下状態は IsChecked プロパティで設定します。True が押下された状態を示します。既定値は False です。
以下は、IsChecked プロパティに True を設定しているので、アプリを起動したタイミングで押下状態になります。
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="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<ToggleButton x:Name="myToggleButton" Content="ToggleButton" IsChecked="True"/>
</StackPanel>
</Window>
C# の例
public MainWindow()
{
this.InitializeComponent();
myToggleButton.IsChecked = true;
}
Please follow and like us:


コメント