LoginSignup
1
0

More than 3 years have passed since last update.

ウィンドウ(フォーム)背景に模様

Posted at

000.png

App.xaml
<Application
    x:Class="SampleApp.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:SampleApp"
    StartupUri="MainWindow.xaml">
    <Application.Resources>

        <!--  既定のButtonスタイル  -->
        <Style TargetType="Button">
            <Setter Property="Margin" Value="8" />
            <Setter Property="Width" Value="150" />
            <Setter Property="HorizontalAlignment" Value="left" />
        </Style>

        <!--  模様付きBorderスタイル  -->
        <Style x:Key="CheckeredPatternStyle" TargetType="Border">
            <Setter Property="Background">
                <Setter.Value>
                    <DrawingBrush
                        Stretch="None"
                        TileMode="Tile"
                        Viewport="0,0,100,100"
                        ViewportUnits="Absolute">
                        <DrawingBrush.Drawing>
                            <DrawingGroup>
                                <GeometryDrawing Brush="Black">
                                    <GeometryDrawing.Geometry>
                                        <RectangleGeometry Rect="0,0,100,100" />
                                    </GeometryDrawing.Geometry>
                                </GeometryDrawing>
                                <GeometryDrawing Brush="ForestGreen">
                                    <GeometryDrawing.Geometry>
                                        <GeometryGroup RenderOptions.EdgeMode="Aliased">
                                            <RectangleGeometry Rect="0,0,50,50" />
                                            <RectangleGeometry Rect="50,50,50,50" />
                                        </GeometryGroup>
                                    </GeometryDrawing.Geometry>
                                </GeometryDrawing>
                            </DrawingGroup>
                        </DrawingBrush.Drawing>
                    </DrawingBrush>
                </Setter.Value>
            </Setter>
        </Style>

    </Application.Resources>
</Application>
MainWindow.xaml
<Window
    x:Class="SampleApp.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:SampleApp"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    Title="MainWindow"
    Width="600"
    Height="400"
    MinWidth="250"
    MinHeight="200"
    ResizeMode="CanResizeWithGrip"
    mc:Ignorable="d">

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition Width="0.4*" />
        </Grid.ColumnDefinitions>

        <Border Grid.ColumnSpan="2" Style="{StaticResource CheckeredPatternStyle}" />

        <StackPanel>
            <Button Content="Button" />
            <Button Content="Button" />
            <Button Content="Button" />
        </StackPanel>

        <TextBox
            Grid.Column="1"
            Margin="8"
            Opacity="0.9"
            Text="こんにちは"
            VerticalScrollBarVisibility="Visible" />
    </Grid>
</Window>
csproj
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net5.0-windows</TargetFramework>
    <UseWPF>true</UseWPF>
  </PropertyGroup>

</Project>
1
0
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
1
0