WPF数据绑定

2021-03-03 21:26

阅读:664

Window x:Class="databinding001.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:databinding001"

mc:Ignorable="d"

x:Name="window"

Title="CLR_Properties_Demo" Height="150" Width="300">

?

Grid Margin="10">

Grid.ColumnDefinitions>

ColumnDefinition Width="Auto"/>

ColumnDefinition Width="15"/>

ColumnDefinition Width="*"/>

Grid.ColumnDefinitions>

Grid.RowDefinitions>

RowDefinition Height="Auto"/>

RowDefinition Height="Auto"/>

RowDefinition Height="10"/>

RowDefinition Height="Auto"/>

Grid.RowDefinitions>

?

TextBlock Text="Your department"

Grid.Row="0" Grid.Column="0"/>

TextBlock Text=":"

Grid.Row="0" Grid.Column="1"

HorizontalAlignment="Center"/>

TextBlock Text="{Binding Department, ElementName = window}"

Margin="0 2"

Grid.Row="0" Grid.Column="2"/>

?

TextBlock Text="Your name"

Grid.Row="1" Grid.Column="0"/>

TextBlock Text=":"

Grid.Row="1" Grid.Column="1"

HorizontalAlignment="Center"/>

TextBox Text="{Binding PersonName, ElementName=window, Mode=TwoWay}"

Margin="0 2"

Grid.Row="1" Grid.Column="2"/>

?

StackPanel Orientation="Horizontal"

HorizontalAlignment="Center"

Grid.Row="3" Grid.Column="0"

Grid.ColumnSpan="3">

Button Content="Submit"

Margin="4" Width="80"

Click="OnSubmit"/>

Button Content="Reset"

Margin="4" Width="80"

Click="OnReset"/>

StackPanel>

Grid>

Window>


评论


亲,登录后才可以留言!