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"> <Window.Resources> <!-- x:Keyを割り当てる --> <SolidColorBrush x:Key='bg' Color='Red' /> </Window.Resources> <WrapPanel> <TextBox Name="textBox" Width="100" Background="{StaticResource bg}"></TextBox> <Button Name="button" Click="button_Click" Background="{StaticResource bg}">入力内容反映</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; } } }