繁体   English   中英

WPF和绑定控件

[英]WPF and binding controls

成功将控件绑定到对象后,如何收集所有具有值的控件?

这是XAML:

<Window
    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:Model="clr-namespace:MyApp.DTO;assembly=MyApp.DTO" mc:Ignorable="d" x:Class="MyApp.Forms.Reference.CustomerTypeForm"
    Title="Customer Type" Height="346" Width="459" WindowStartupLocation="CenterOwner" ShowInTaskbar="False" ScrollViewer.VerticalScrollBarVisibility="Disabled" ResizeMode="NoResize" Loaded="Window_Loaded">
    <DockPanel LastChildFill="True">
        <Grid>
        <Canvas>
            <Label Content="Number:" HorizontalAlignment="Left" Margin="87,33,0,0" VerticalAlignment="Top"/>
            <TextBox x:Name="txtNumber" HorizontalAlignment="Left" Height="24" Margin="185,36,0,211" Text="{Binding Number, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" VerticalAlignment="Center" Width="76" KeyDown="txtNumber_KeyDown"/>

            <Label Content="Description:" HorizontalAlignment="Left" VerticalAlignment="Top" Canvas.Left="87" Canvas.Top="62"/>
            <TextBox x:Name="txtDescription" HorizontalAlignment="Left" Height="24" Margin="185,64,0,183" Text="{Binding Description, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" VerticalAlignment="Center" Width="236"/>

            <Label Content="Abbr:" HorizontalAlignment="Left" VerticalAlignment="Top" Canvas.Left="87" Canvas.Top="91"/>
            <TextBox x:Name="txtAbbr" HorizontalAlignment="Left" Height="24" Margin="185,93,0,154" Text="{Binding Abbr, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" VerticalAlignment="Center" Width="75"/>
        </Canvas>
        </Grid>
    </DockPanel>
</Window>

WPF以数据为中心...这意味着我们使用数据而不是UI控件 将对象的数据绑定到一个或多个UI控件后,您就可以省去UI控件,然后再使用这些数据

因此,您想知道UI的值吗? 只需查看数据绑定到UI控件的对象的属性而不是UI控件的值即可

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM