1

私の Silverlight フォームでは、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>

ご覧のとおり、グリッドにはいくつかのフィールドがあり、すべて必須です ( txtCodiceFiscale16 文字の英数字)。My Service Reference では、 Persona(person) Documento(Document) とStrutturaSanitaria(HealthFacility) の 3 つの主要なクラスが定義されています。周りを読んで、検証を実行する「より良い」方法は、データバインディングを使用することであることがわかりました(これは、従来の WinForms で簡単に実行できます)。おそらく、まだ習得していない MVVM パターンと関係があります。

フォーム ボタンの Click イベントでコードを手動で検証する従来の方法ではなく、フォームとそのテキスト ボックスをデータ コンテキスト オブジェクトのプロパティにバインドできることを学びました。

問題

3 つのデータ オブジェクトが必要です。これまでに見つけたすべての例は、ルート コントロールに割り当てられた 1 つのオブジェクトのみを示しています (私の場合、2 番目のタブは Web サービスからの結果を表示し、適切にバインドされるため、最初の TabItem にオブジェクトをバインドする必要があります)。コントロールを複数のオブジェクトにバインドすることは可能ですか? (複数のデータオブジェクトを指定するための構文がわかりません) そうでない場合は、少なくともこのようなクラスにバインドして、ツリー内の各プロパティを参照できますか?

public class DataContainer {
    public Persona Persona{get; set;}
    public Documento Documento {get; set;}
    public StrutturaSanitaria Struttura {get; set;}
}

これにより、すべての値を具体化するクラスを定義するという頭痛の種から解放されます。したがって、少なくともクリックするSubmitと、すべてのオブジェクトにデータが入力されます。

または、コードが安価で実行可能な他のソリューションはありますか? 何冊か本を見つけようとしていますが、締め切りまでに全部読む時間がありません。その背後にあるメカニズムを理解するのに役立つ、または単にそれらを簡潔に説明するのに役立つ、データ検証に関する優れたチュートリアルを誰かに見せてもらえますか?

4

1 に答える 1

1

Colin Eberhardt は、数年前に Silverlight の複数バインディングに関するブログ記事を公開しました。多分これはいくつかの助けになるでしょうか?

これは基本的に、WPF MultiBindingクラスで適用されるのと同じアプローチです。

于 2012-07-01T12:09:43.457 に答える