2010-01-04 24 views
0

下面是我的對象作爲XML的示例。由於隱私,我不得不拿出實際的數據,但是你應該明白事情的要點。目前我有約束力的工作很好,但我不能得到一個盒子來填寫必要的Granchild信息。列表框工作正常,它可能是一個邏輯問題,我只是沒有看到。如何綁定子對象的子對象?

每個醫生可以有一個或多個doctoroffices,但每個doctoroffice只屬於一個集團是一家集本身。 Nettiers啓用了一個IdSource屬性,該屬性允許您定義孫元素而不是遍歷層次結構。這就是我正在填寫的內容。GroupIdSource正在被填充,但綁定並沒有抓住它。

<TextBlock Grid.Row="0" Grid.Column="1" Background="blue" FontSize="12" 
      FontWeight="Bold" > 
    **<Label Content="{Binding Path=GroupIdSource.GroupName}**"/> 




<Doctors xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
     <EntityState> </EntityState> 
     <Id> </Id> 
     <DisplayName> </DisplayName> 
     <FirstName> </FirstName> 
     <LastName> </LastName> 
     <MiddleName> </MiddleName> 
     <Credentials xsi:nil="true" /> 
     <AddDate> </AddDate> 
     <AddUserId> </AddUserId> 
     <ChangeDate> </ChangeDate> 
     <ChangeUserId> </ChangeUserId> 
     <ProviderTypeId> </ProviderTypeId> 
     <SpecialtyId> </SpecialtyId> 
     <DoctorOfficesCollection> 
     <DoctorOffices> 
      <EntityState> </EntityState> 
      <DoctorsId> </DoctorsId> 
      <ForeignId> </ForeignId> 
      <OriginalForeignId> </OriginalForeignId> 
      <Active> </Active> 
      <Address1> </Address1> 
      <Address2> </Address2> 
      <Address3> </Address3> 
      <City> </City> 
      <State> </State> 
      <Zip> </Zip> 
      <PrimaryPhone> </PrimaryPhone> 
      <Fax> </Fax> 
      <AlternatePhone1 xsi:nil="true" /> 
      <AlternatePhone2> </AlternatePhone2> 
      <OfficeName xsi:nil="true" /> 
      <OfficeDisplayName> </OfficeDisplayName> 
      <AddDate> </AddDate> 
      <AddUserId> </AddUserId> 
      <ChangeDate> </ChangeDate> 
      <ChangeUserId> </ChangeUserId> 
      <CommonOfficeIdentifier> </CommonOfficeIdentifier> 
      <GroupId> </GroupId> 
      <OfficeNotesCollection /> 
      <HasChanges> </HasChanges> 
      <GroupIdSource> 
      <EntityState> </EntityState> 
      <Id> </Id> 
      <GroupCode> </GroupCode> 
      <GroupName> </GroupName> 
      <DoctorOfficesCollection /> 
      </GroupIdSource> 
     </DoctorOffices> 
     </DoctorOfficesCollection> 
     <DoctorTaxonomyCollection> 
     <DoctorTaxonomy> 
      <EntityState> </EntityState> 
      <DoctorId> </DoctorId> 
      <OriginalDoctorId> </OriginalDoctorId> 
      <TaxonomySpecializationId> </TaxonomySpecializationId> 
      <OriginalTaxonomySpecializationId> </OriginalTaxonomySpecializationId> 
      <TaxonomyTypeId> </TaxonomyTypeId> 
      <OriginalTaxonomyTypeId> </OriginalTaxonomyTypeId> 
      <TaxonomyClassificationId> </TaxonomyClassificationId> 
      <OriginalTaxonomyClassificationId> </OriginalTaxonomyClassificationId> 
      <AddDate> </AddDate> 
      <AddUserId> </AddUserId> 
      <ChangeDate xsi:nil="true" /> 
      <ChangeUserId xsi:nil="true" /> 
     </DoctorTaxonomy> 
     </DoctorTaxonomyCollection> 
     <DoctorHome> 
     <EntityState> </EntityState> 
     <DoctorsId> </DoctorsId> 
     <OriginalDoctorsId> </OriginalDoctorsId> 
     <Address1> </Address1> 
     <Address2 xsi:nil="true" /> 
     <Address3 xsi:nil="true" /> 
     <City> </City> 
     <State> </State> 
     <Zip> </Zip> 
     <PrimaryPhone xsi:nil="true" /> 
     <Fax xsi:nil="true" /> 
     <AddDate> </AddDate> 
     <AddUserId> </AddUserId> 
     <ChangeDate> </ChangeDate> 
     <ChangeUserId> </ChangeUserId> 
     </DoctorHome> 
     <DoctorLicenses> 
     <EntityState> </EntityState> 
     <DoctorsId> </DoctorsId> 
     <OriginalDoctorsId> </OriginalDoctorsId> 
     <LicenseNumber> </LicenseNumber> 
     <DeaNumber xsi:nil="true" /> 
     <NpiNumber> </NpiNumber> 
     <Bc_StateLicenseNumber> </Bc_StateLicenseNumber> 
     <ChampusIdNumber> </ChampusIdNumber> 
     <MedicaidLicenseNumber> </MedicaidLicenseNumber> 
     <Medicaid1500LicenseNumber> </Medicaid1500LicenseNumber> 
     <MedicareLicenseNumber> </MedicareLicenseNumber> 
     <MedchiNumber xsi:nil="true" /> 
     <UpinNumber> </UpinNumber> 
     <AddDate> </AddDate> 
     <AddUserId> </AddUserId> 
     <ChangeDate> </ChangeDate> 
     <ChangeUserId> </ChangeUserId> 
     </DoctorLicenses> 
     <TaxonomyTypeIdTaxonomyClassificationIdTaxonomySpecializationIdTaxonomySpecializationCollection_From_DoctorTaxonomy /> 
     <SpecialtyIdSource> 
     <EntityState> </EntityState> 
     <Id> </Id> 
     <OriginalId> </OriginalId> 
     <Description> </Description> 
     <Flag> </Flag> 
     <DoctorsCollection /> 
     </SpecialtyIdSource> 
     <ProviderTypeIdSource> 
     <EntityState> </EntityState> 
     <Id> </Id> 
     <OriginalId> </OriginalId> 
     <Description> </Description> 
     <Flag> </Flag> 
     <DoctorsCollection /> 
     </ProviderTypeIdSource> 
     <EditingUser> </EditingUser> 
    </Doctors> 

這裏是我的完整XAML幫助了。我有一個 。數據綁定如上所述,但是它與數據視圖綁定的方式有所不同。它直接綁定到對象,然後其子......你可以看到它在NPINumber第一列表框...

<Grid x:Class="Views.DoctorMasterDetailView" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:ad="clr-namespace:WavelengthIS.Infrastructure.AttachedProperties;assembly=WavelengthIS.Infrastructure" 
     xmlns:clr="clr-namespace:System;assembly=mscorlib" 
     xmlns:c="clr-namespace:WavelengthIS.Infrastructure.Converters;assembly=WavelengthIS.Infrastructure" 
     xmlns:vw="clr-namespace:WavelengthIS.Referee.Modules.DoctorMasterDetail.ViewModel" 
     MinHeight="480" MinWidth="640"> 
    <Grid.Resources> 
     <c:StringTrimmingConverter x:Key="trimmingConverter" /> 
     <c:CombineStringsConverter x:Key="CombineStringsConverter"/> 
     <c:TextToVisibilityConverter x:Key="TextToVisibilityConverter"/> 
    </Grid.Resources> 
    <Grid.DataContext> 
     <vw:DoctorMasterDetailViewModel/> 
    </Grid.DataContext> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition MinWidth="100" Width="150" /> 
     <ColumnDefinition/> 
    </Grid.ColumnDefinitions> 
    <GridSplitter Grid.Column="0" 
       HorizontalAlignment="Right" 
       VerticalAlignment="Stretch" 
       Background="Black" 
       ShowsPreview="false" 
       Width="2"/> 
    <ListBox x:Name="DoctorHeaderList" Grid.Column="0" Background="Green" Margin="0,0,2,0" 
      ItemsSource="{Binding DoctorsList}" 
      SelectedItem="{Binding SelectedDoctor}"> 
     <ListBox.ItemTemplate> 
      <DataTemplate> 
       <StackPanel> 
        <Border BorderBrush="Black" 
         BorderThickness="1" 
         Background="White" 
         Width="{Binding ElementName=DoctorHeaderList, Path=ActualWidth}" 
         CornerRadius="5" 
         Margin="5" 
         Padding="5"> 
         <TextBlock Text="{Binding Path=DisplayName, Converter={StaticResource trimmingConverter}}" Foreground="Black" FontSize="14"/> 
        </Border> 
        <TextBlock Text="{Binding Path=DoctorLicenses.NpiNumber, StringFormat='NPI Number: {0}'}"/> 
       </StackPanel> 
      </DataTemplate> 
     </ListBox.ItemTemplate> 
    </ListBox> 
    <ListBox x:Name="DoctorOfficesList" Grid.Column="1" Background="Orange" 
      ItemsSource="{Binding Path=SelectedDoctor.DoctorOfficesCollection}" HorizontalContentAlignment="Stretch"> 
    <!--DESIGN TIME BINDING ONLY!!!!!!!!!!!!!!!!!!!!--> 
    <!--<ListBox x:Name="DoctorOfficesList" Grid.Column="1" Background="Orange" 
      ItemsSource="{Binding Path=Offices}" HorizontalContentAlignment="Stretch">--> 
     <ListBox.ItemTemplate> 
      <DataTemplate> 
       <Border BorderThickness="2" BorderBrush="Black" CornerRadius="5" Margin="1" > 
        <Grid> 
         <Grid.RowDefinitions> 
          <RowDefinition MinHeight="10" /> 
          <RowDefinition MinHeight="35" /> 
         </Grid.RowDefinitions> 
         <Grid.ColumnDefinitions> 
          <ColumnDefinition /> 
          <ColumnDefinition /> 
         </Grid.ColumnDefinitions> 
         <TextBlock Grid.Row="0" Grid.Column="0" Background="red" > 
          <Label Content="Physician Number: "/> 
          <Label Content="{Binding Path=ForeignId, StringFormat='Physician Number: {0}'}" 
            FontSize="12" FontWeight="Bold" /> 
         </TextBlock> 
         <TextBlock Grid.Row="0" Grid.Column="1" Background="blue" FontSize="12" FontWeight="Bold" > 
          <Label Content="{Binding Path=GroupIdSource.GroupName}"/> 
         </TextBlock> 
         <StackPanel Orientation="Horizontal" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Background="green"> 
          <StackPanel Orientation="Vertical" > 
           <TextBlock Margin="5,0,0,0" Text="{Binding Path=Address1, Converter={StaticResource trimmingConverter}}"/> 
           <TextBlock Margin="5,0,0,0" Text="{Binding Path=Address2, Converter={StaticResource trimmingConverter}}"/> 
           <TextBlock Margin="5,0,0,0" Text="{Binding Path=Address3, Converter={StaticResource trimmingConverter}}"/> 
           <TextBlock Margin="5,0,0,0"> 
          <TextBlock.Text> 
           <MultiBinding StringFormat="{}{0}, {1} {2}"> 
            <Binding Path="City"/> 
            <Binding Path="State"/> 
            <Binding Path="Zip"/> 
           </MultiBinding> 
          </TextBlock.Text> 
           </TextBlock> 
          </StackPanel> 
          <StackPanel Orientation="Vertical" Margin="5,0,0,0" FlowDirection="RightToLeft"> 
           <TextBlock Text="{Binding Path=PrimaryPhone, StringFormat='Primary Phone: {0}'}"/> 
           <TextBlock Text="{Binding Path=Fax, StringFormat='Fax: {0}'}" /> 
           <TextBlock Text="{Binding Path=AlternatePhone1, StringFormat='Alternate Phone 1: {0}'}" 
             Visibility="{Binding Path=AlternatePhone1, Converter={StaticResource TextToVisibilityConverter}}" /> 
           <TextBlock Text="{Binding Path=AlternatePhone2, StringFormat='Alternate Phone 2: {0}'}" 
             Visibility="{Binding Path=AlternatePhone2, Converter={StaticResource TextToVisibilityConverter}}" /> 
          </StackPanel> 
         </StackPanel> 
        </Grid> 
       </Border> 
      </DataTemplate> 
     </ListBox.ItemTemplate> 
    </ListBox> 


</Grid> 

回答

0

我終於得到這個行爲後,閱讀很多。但事實上,在我的代碼中沒有任何變化,除非我錯過了關於wpf控件如何工作的內容。無論如何,我可能會慢慢放鬆這些變化,看看我是否可以複製這個問題。以下是任何可能遇到類似問題並需要知道如何操作的人員的工作代碼。

<GroupBox 
     x:Name="DoctorOffices" 
     Header="Doctor Offices" 
     DataContext="{Binding Path=SelectedDoctor.DoctorOfficesCollection}" 
     Grid.Column="1" 
     Grid.Row="0"> 
     <ListBox x:Name="DoctorOfficesListBox" Background="Green" 
      ItemsSource="{Binding}" 
       IsSynchronizedWithCurrentItem="true"> 
      <ListBox.ItemTemplate> 
       <DataTemplate> 
        <Border BorderThickness="2" BorderBrush="Black" CornerRadius="5" Margin="1" > 
         <Grid> 
          <Grid.RowDefinitions> 
           <RowDefinition MinHeight="10" /> 
           <RowDefinition MinHeight="35" /> 
          </Grid.RowDefinitions> 
          <Grid.ColumnDefinitions> 
           <ColumnDefinition /> 
           <ColumnDefinition /> 
          </Grid.ColumnDefinitions> 
          <TextBlock Grid.Row="0" Grid.Column="0" Background="red" > 
          <Label Content="Physician Number: "/> 
          <Label Content="{Binding Path=ForeignId, StringFormat='Physician Number: {0}'}" 
            FontSize="12" FontWeight="Bold" /> 
          </TextBlock> 
          <TextBlock Background="white" Grid.Row="0" Grid.Column="1" 
             Text="{Binding Path=GroupIdSource.GroupName}" /> 
          <StackPanel Orientation="Horizontal" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Background="green"> 
           <StackPanel Orientation="Vertical" > 
            <TextBlock Margin="5,0,0,0" Text="{Binding Path=Address1, Converter={StaticResource trimmingConverter}}"/> 
            <TextBlock Margin="5,0,0,0" Text="{Binding Path=Address2, Converter={StaticResource trimmingConverter}}"/> 
            <TextBlock Margin="5,0,0,0" Text="{Binding Path=Address3, Converter={StaticResource trimmingConverter}}"/> 
            <TextBlock Margin="5,0,0,0"> 
          <TextBlock.Text> 
           <MultiBinding StringFormat="{}{0}, {1} {2}"> 
            <Binding Path="City"/> 
            <Binding Path="State"/> 
            <Binding Path="Zip"/> 
           </MultiBinding> 
          </TextBlock.Text> 
            </TextBlock> 
           </StackPanel> 
           <StackPanel Orientation="Vertical" Margin="5,0,0,0" FlowDirection="RightToLeft"> 
            <TextBlock Text="{Binding Path=PrimaryPhone, StringFormat='Primary Phone: {0}'}"/> 
            <TextBlock Text="{Binding Path=Fax, StringFormat='Fax: {0}'}" /> 
            <TextBlock Text="{Binding Path=AlternatePhone1, StringFormat='Alternate Phone 1: {0}'}" 
             Visibility="{Binding Path=AlternatePhone1, Converter={StaticResource TextToVisibilityConverter}}" /> 
            <TextBlock Text="{Binding Path=AlternatePhone2, StringFormat='Alternate Phone 2: {0}'}" 
             Visibility="{Binding Path=AlternatePhone2, Converter={StaticResource TextToVisibilityConverter}}" /> 
           </StackPanel> 
          </StackPanel> 
         </Grid> 
        </Border> 
       </DataTemplate> 
      </ListBox.ItemTemplate> 
     </ListBox> 
    </GroupBox> 

,你可以看到真正的唯一的事情,我已經做了不同的充本身就是添加一個組框設置爲列表框的原始數據綁定,然後更改的ItemSource到{}綁定。沒有其他變化應該有任何實際效果。

+0

也許與當前項目同步的是票據。我不認爲我在另一個角度看到了這個水平。但我會驗證這一點。 – ecathell 2010-01-05 18:26:19

0

當對XML數據源綁定,你應該使用的XPath代替Path到達所需的元素/屬性。

編輯:您需要以某種方式設置你的目標是控制在DataContext(或其祖先之一),那麼你可以參考的任何財產或它的嵌套屬性。例如在你的情況下:

...{Binding Path=DoctorOfficesCollection[0].GroupIdSource.GroupName}... 
+0

實際的元素不是xml。我將我的對象的結構轉換爲xml,只是爲了幫助理解對象的佈局。 – ecathell 2010-01-04 21:35:30

+0

編輯答案.. – 2010-01-04 22:29:29

+0

好吧,我已經將Listbox的itemsource設置爲{binding path = selecteddoctor.officecollection} 有沒有辦法我必須操縱單個listitems來知道要獲取哪個集合對象實例?我認爲我的NPI例子很相似,但我記得那張表格實際上是1:1的關係,而不是1:很多... – ecathell 2010-01-05 01:19:58