Architect's Log

I'm a Cloud Architect. I'm highly motivated to reduce toils with driving DevOps.

コントロールを操作する

MyWindow.xamlファイルのクラス名を指定する

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow">
    <WrapPanel>
        <TextBox Name="textBox" Width="100"></TextBox>
        <Button Name="button" Click="button_Click">入力内容反映</Button>
        <TextBlock Name="textBlock" />
    </WrapPanel>
</Window>

MyWindow.xaml.csファイルを作成する

using System.Windows;

namespace WpfApplication1 {
    public partial class MainWindow : Window {
        public MainWindow() {
            InitializeComponent();
        }

        private void button_Click(object sender, RoutedEventArgs e) {
            this.textBlock.Text = this.textBox.Text;
        }
    }
}

HelloWorld.csprojファイルにxaml.csファイルを追加する

<Project
    DefaultTargets="Build"
    xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

    <PropertyGroup>
        <Configuration>Debug</Configuration>
        <Platform>AnyCPU</Platform>
        <RootNamespace>HelloWorld</RootNamespace>
        <AssemblyName>HelloWorld</AssemblyName>
        <OutputType>WinExe</OutputType>
        <OutputPath>.\bin\Debug\</OutputPath>
    </PropertyGroup>

    <ItemGroup>
        <Reference Include="System" />
        <Reference Include="WindowsBase" />
        <Reference Include="PresentationCore" />
        <Reference Include="PresentationFramework" />
    </ItemGroup>
    
    <ItemGroup>
        <Compile Include="MyWindow.xaml.cs" />
        <Page Include="MyWindow.xaml" />
        <ApplicationDefinition Include="App.xaml" />
    </ItemGroup>

    <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
    <Import Project="$(MSBuildBinPath)\Microsoft.WinFX.targets" />
</Project>

ビルド


ボタンクリック前


ボタンクリック後