我的 Silverlight 表单需要为 3 个类的对象中的字段输入值,这 3 个类将共同请求调用 Web 服务
GUI 的正在进行中的代码如下
<UserControl x:Class="ClientSanitaro.MainPage"
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"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="600" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" xmlns:my="clr-namespace:It.Unina.MasterICT.ClientSanitario.Controls" xmlns:data="clr-namespace:It.Unina.MasterICT.ClientSanitario.Data" Loaded="UserControl_Loaded">
<sdk:TabControl Height="400" HorizontalAlignment="Center" Margin="10,10,0,0" Name="tabControl" VerticalAlignment="Top" Width="550">
<sdk:TabItem Header="Upload documenti" Name="tabUpload">
<sdk:TabItem.DataContext>
<data:PazienteGui/>
</sdk:TabItem.DataContext>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.Resources>
<Style TargetType="TextBox">
<Setter Property="Margin" Value="2"/>
</Style>
<Style TargetType="sdk:Label">
<Setter Property="Margin" Value="2"/>
</Style>
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="5*"/>
</Grid.ColumnDefinitions>
<TextBox Height="23" HorizontalAlignment="Left" Name="txtUploadEndpoint" Width="300" Grid.Column="1" VerticalAlignment="Center" />
<sdk:Label Height="23" HorizontalAlignment="Right" Name="lblUploadEndpoint" VerticalAlignment="Center" Width="80" Content="URL endpoint" Grid.Column="0" />
</Grid>
<Grid Grid.Row="1" Margin="15">
<Grid.Resources>
<Style TargetType="TextBox">
<Setter Property="Margin" Value="3"/>
</Style>
<Style TargetType="sdk:Label">
<Setter Property="Margin" Value="3"/>
</Style>
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="2*"/>
</Grid.ColumnDefinitions>
<sdk:Label Content="Persona" FontWeight="Bold" HorizontalAlignment="Left" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2"/>
<sdk:Label Content="Cognome" Grid.Row="1" Grid.Column="0" HorizontalAlignment="Right"/>
<TextBox Name="txtPersonaCognome" Grid.Row="1" Grid.Column="1" HorizontalAlignment="Stretch"/>
<sdk:Label Content="Nome" Grid.Row="2" Grid.Column="0" HorizontalAlignment="Right"/>
<TextBox Name="txtNome" Grid.Row="2" Grid.Column="1" HorizontalAlignment="Stretch"/>
<sdk:Label Content="Codice Fiscale" Grid.Row="3" Grid.Column="0" HorizontalAlignment="Right" />
<TextBox Name="txtPersonaCodiceFiscale" Grid.Row="3" Grid.Column="1" HorizontalAlignment="Stretch"/>
<sdk:Label Content="Residenza" Grid.Row="4" Grid.Column="0" HorizontalAlignment="Right"/>
<TextBox Name="txtPazienteResidenza" Grid.Row="4" HorizontalAlignment="Stretch" Grid.Column="1"/>
<sdk:Label Content="Struttura Sanitaria" Grid.Row="5" Grid.Column="0" HorizontalAlignment="Left" Grid.ColumnSpan="2" FontWeight="Bold" />
<sdk:Label Content="Nome" Grid.Row="6" Grid.Column="0" HorizontalAlignment="Right"/>
<TextBox Name="txtStrutturaNome" Grid.Row="6" Grid.Column="1" HorizontalAlignment="Stretch"/>
<sdk:Label Content="Indirizzo" Grid.Row="7" Grid.Column="0" HorizontalAlignment="Right"/>
<TextBox Name="txtStrutturaIndirizzo" Grid.Row="7" Grid.Column="1" HorizontalAlignment="Stretch"/>
<sdk:Label Content="Documento Sanitario" Grid.Row="0" Grid.Column="2" FontWeight="Bold" HorizontalAlignment="Left" Grid.ColumnSpan="2"/>
<sdk:Label Content="Contenuto" Grid.Row="1" Grid.Column="2" HorizontalAlignment="Right"/>
<ComboBox Name="cmbTipoContenuto" Grid.Row="1" Grid.Column="3" HorizontalAlignment="Stretch"/>
<sdk:Label Content="Tipo MIME" Grid.Row="2" Grid.Column="2" HorizontalAlignment="Right"/>
<TextBlock Name="lblMimeType" Grid.Row="2" Grid.Column="3" HorizontalAlignment="Stretch" VerticalAlignment="Center"/>
<sdk:Label Content="File" Grid.Row="4" Grid.Column="2" HorizontalAlignment="Right"/>
<my:FileUpload Grid.Column="3" Grid.Row="4" Grid.RowSpan="2" HorizontalAlignment="Stretch" x:Name="fileUpload" VerticalAlignment="Top" FileUploaded="fileUpload_FileUploaded" FileRemoved="fileUpload_FileRemoved" />
<Button Content="Upload" Grid.Column="3" Grid.Row="7" HorizontalAlignment="Stretch" Name="btnUpload" VerticalAlignment="Stretch" Click="btnUpload_Click" />
</Grid>
</Grid>
</sdk:TabItem>
<sdk:TabItem Header="Ricerca documenti" Name="tabRicerca">
<Grid></Grid>
</sdk:TabItem>
</sdk:TabControl>
如您所见,在网格中,我有几个字段,都是必需的(txtCodiceFiscale
长度为 16 个字母数字字符)。我的服务参考定义了 3 个主要类:Persona
(person) Documento
(Document) 和StrutturaSanitaria
(HealthFacility)。环顾四周,我发现执行验证的“更好”方法是使用数据绑定(我可以在经典的 WinForms 中轻松做到这一点),也许它与我尚未掌握的 MVVM 模式有关。
我了解到,我可以将表单及其文本框绑定到数据上下文对象的属性,而不是让表单按钮的 Click 事件手动验证代码。
问题
我需要 3 个数据对象。到目前为止,我发现的所有示例都只显示了一个分配给根控件的对象(在我的情况下,我需要将该对象绑定到第一个 TabItem,因为第二个选项卡应该显示来自 Web 服务的结果并且将被正确绑定)。是否可以将控件绑定到多个对象?(我不知道指定多个数据对象的语法)如果不知道,我至少可以将它绑定到这样的类并引用树中的每个属性吗?
public class DataContainer {
public Persona Persona{get; set;}
public Documento Documento {get; set;}
public StrutturaSanitaria Struttura {get; set;}
}
它为我省去了定义一个包含所有值的类的麻烦,所以至少当我单击时,Submit
我所有的对象都充满了数据。
或者,您是否有其他可行且代码成本低廉的解决方案?我正在寻找一些书籍,但我没有时间在截止日期之前阅读它们。有人可以给我看一个关于数据验证的好教程,帮助我理解它背后的机制,或者简单地向我解释一下吗?