0
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

WPF 画面定義ひな型

Last updated at Posted at 2020-08-27

■1. 入力画面

wpftmp1.png

サンプル1
<Window
    x:Class="Sample1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:local="clr-namespace:Sample1"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    Title="MainWindow"
    Width="500"
    Height="350"
    ResizeMode="CanResizeWithGrip"
    mc:Ignorable="d">
    <Window.Resources>
        <!--  標準ボタンスタイル  -->
        <Style x:Key="StandardButtonStyle" TargetType="Button">
            <Setter Property="Margin" Value="8" />
        </Style>
        <!--  既定ボタンスタイル  -->
        <Style BasedOn="{StaticResource StandardButtonStyle}" TargetType="Button" />
        <!--  遷移ボタンスタイル  -->
        <Style
            x:Key="TransitionButton"
            BasedOn="{StaticResource StandardButtonStyle}"
            TargetType="Button">
            <Setter Property="Width" Value="100" />
        </Style>

        <!--  既定ラベルスタイル  -->
        <Style TargetType="Label">
            <Setter Property="Margin" Value="8,8,8,0" />
        </Style>

        <!--  標準テキストボックススタイル  -->
        <Style x:Key="StandardTextBoxStyle" TargetType="TextBox">
            <Setter Property="Margin" Value="8,0,8,8" />
        </Style>
        <!--  既定テキストボックススタイル  -->
        <Style BasedOn="{StaticResource StandardTextBoxStyle}" TargetType="TextBox" />
        <!--  小サイズテキストボックススタイル  -->
        <Style
            x:Key="SizeSText"
            BasedOn="{StaticResource StandardTextBoxStyle}"
            TargetType="TextBox">
            <Setter Property="Width" Value="100" />
            <Setter Property="HorizontalAlignment" Value="Left" />
        </Style>
        <!--  中サイズテキストボックススタイル  -->
        <Style
            x:Key="SizeMText"
            BasedOn="{StaticResource StandardTextBoxStyle}"
            TargetType="TextBox">
            <Setter Property="Width" Value="200" />
            <Setter Property="HorizontalAlignment" Value="Left" />
        </Style>
    </Window.Resources>

    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <!--  入力項目エリア  -->
        <StackPanel>
            <Label Content="項目あ(_A)" Target="{Binding ElementName=ItemA}" />
            <TextBox x:Name="ItemA" Text="" />

            <Label Content="項目い(_B)" Target="{Binding ElementName=ItemB}" />
            <TextBox x:Name="ItemB" Text="" />

            <Label Content="項目う(_C)" Target="{Binding ElementName=ItemC}" />
            <TextBox
                x:Name="ItemC"
                Style="{StaticResource SizeSText}"
                Text="" />

            <Label Content="項目え(_D)" Target="{Binding ElementName=ItemD}" />
            <TextBox
                x:Name="ItemD"
                Style="{StaticResource SizeMText}"
                Text="" />
        </StackPanel>

        <!--  ボタンエリア  -->
        <StackPanel
            Grid.Row="1"
            HorizontalAlignment="Right"
            Orientation="Horizontal">
            <Button
                Content="OK"
                IsDefault="True"
                Style="{StaticResource TransitionButton}" />
            <Button
                Content="キャンセル"
                IsCancel="True"
                Style="{StaticResource TransitionButton}" />
        </StackPanel>
    </Grid>
</Window>

■2. パス入力

wpftmp2.png

サンプル2
<Window
    x:Class="Sample2.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:local="clr-namespace:Sample2"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    Title="MainWindow"
    Width="500"
    Height="180"
    ResizeMode="CanResizeWithGrip"
    mc:Ignorable="d">
    <Window.Resources>
        <!--  既定ラベルスタイル  -->
        <Style TargetType="Label">
            <Setter Property="Margin" Value="8,8,8,0" />
        </Style>
        <!-- 既定テキストボックススタイル -->
        <Style TargetType="TextBox">
            <Setter Property="Margin" Value="8,0,8,8"/>
        </Style>
        <!-- ボタンスタイル -->
        <Style TargetType="Button" x:Key="SubButtonStyle">
            <Setter Property="Width" Value="45"/>
            <Setter Property="Margin" Value="0,0,8,8"/>
        </Style>
    </Window.Resources>

    <StackPanel>
        <Label Content="パス(_P)" Target="{Binding ElementName=PathText}"/>
        <DockPanel>
            <Button Content="参照" DockPanel.Dock="Right" Style="{StaticResource SubButtonStyle}"/>
            <TextBox x:Name="PathText" Text=""/>
        </DockPanel>
    </StackPanel>
</Window>
0
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?