「東雲 忠太郎」の平凡な日常のできごと

「東雲 忠太郎」の平凡な日常のできごと

2024.04.20
XML
カテゴリ: C#.NET


ボタンの高さと幅をテンプレートで定義するには、テンプレート内で `MinWidth`, `MinHeight`, `MaxWidth`, `MaxHeight`, `Width`, `Height` プロパティを設定します。これらのプロパティを使用して、ボタンのサイズを制御します。


以下に、C# WPF でボタンの高さと幅をテンプレートで定義する方法を示します。


```xml

<Window x:Class="YourNamespace.MainWindow"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        Title="Button Template Sample" Height="200" Width="300">

    <Window.Resources>

        <Style x:Key="CustomButtonStyle" TargetType="Button">

            <Setter Property="MinWidth" Value="100"/>

            <Setter Property="MinHeight" Value="40"/>

            <Setter Property="MaxWidth" Value="200"/>

            <Setter Property="MaxHeight" Value="80"/>

            <Setter Property="Width" Value="120"/>

            <Setter Property="Height" Value="60"/>

            <!-- 他のスタイル設定 -->

            <Setter Property="Template">

                <Setter.Value>

                    <ControlTemplate TargetType="Button">

                        <Border Background="{TemplateBinding Background}"

                                BorderBrush="{TemplateBinding BorderBrush}"

                                BorderThickness="{TemplateBinding BorderThickness}"

                                Padding="{TemplateBinding Padding}">

                            <ContentPresenter HorizontalAlignment="Center"

                                              VerticalAlignment="Center"/>

                        </Border>

                        <!-- トリガーなどの追加 -->

                    </ControlTemplate>

                </Setter.Value>

            </Setter>

        </Style>

    </Window.Resources>

    <Grid>

        <Button Content="Click Me" Style="{StaticResource CustomButtonStyle}" HorizontalAlignment="Center" VerticalAlignment="Center"/>

    </Grid>

</Window>

```


この例では、`CustomButtonStyle` という名前のスタイルでボタンのサイズを定義しています。`MinWidth`, `MinHeight`, `MaxWidth`, `MaxHeight`, `Width`, `Height` プロパティを設定することで、ボタンのサイズが固定されます。


必要に応じて、他のスタイル設定やテンプレートのカスタマイズも行うことができます。






お気に入りの記事を「いいね!」で応援しよう

Last updated  2024.04.20 13:40:08


【毎日開催】
15記事にいいね!で1ポイント
10秒滞在
いいね! -- / --
おめでとうございます!
ミッションを達成しました。
※「ポイントを獲得する」ボタンを押すと広告が表示されます。
x

© Rakuten Group, Inc.
Create a Mobile Website
スマートフォン版を閲覧 | PC版を閲覧
Share by: