WPF数据绑定
Posted ifconfig
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WPF数据绑定相关的知识,希望对你有一定的参考价值。
MainWindow.xaml
主要注意的是三个地方(现在我对WPF基础知识不怎么数量)
- 添加x:name 这个我难以理解,于是百度了一下:
https://blog.csdn.net/fantasiax/article/details/3499767
?
<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> ? <!-- Row 0 --> <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"/> ? <!-- Row 1 --> <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"/> ? <!-- Row 3 --> <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> |
以上是关于WPF数据绑定的主要内容,如果未能解决你的问题,请参考以下文章