<Window x:Class="WpfApp1.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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800" Loaded="Window_Loaded">
<Grid Name="grid1">
<Grid.Background>
<LinearGradientBrush>
<LinearGradientBrush.GradientStops>
<GradientStop Offset="0.00" Color="Red"/>
<GradientStop Offset="0.50" Color="Indigo"/>
<GradientStop Offset="1.00" Color="Violet"/>
</LinearGradientBrush.GradientStops>
</LinearGradientBrush>
</Grid.Background>
<Button Content="<Button1>" HorizontalAlignment="Left" Margin="278,154,0,0" VerticalAlignment="Top"/>
<Button Content="Button2" HorizontalAlignment="Left" Margin="278,259,0,0" VerticalAlignment="Top"/>
<Button Content="Button3" HorizontalAlignment="Left" Margin="540,217,0,0" VerticalAlignment="Top"/>
<TextBox HorizontalAlignment="Left" Margin="208,21,0,0" Text="This is a long long long long long long text" xml:space="preserve" VerticalAlignment="Top"/>
</Grid>
</Window>
后台代码
using System.Windows;
namespace WpfApp1
{
/// <summary>
/// MainWindow.xaml 的交互逻辑
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
this.Title = this.grid1.Name;
}
}
}