views:

132

answers:

2

Below is a sample of my object as XML. I had to take out the actual data because of Privacy, but you should get the gist of things. Currently I have binding working pretty well, but I cant get a box to fill with the necessary Granchild information. The list box is working correctly, and its probably a logical issue on my end that I am just not seeing.

each doctor can have one or more doctoroffices, but each doctoroffice belongs to only one group which is a collection in itself. Nettiers enables an IdSource property that allows you to have the grandchild element defined instead of walking the hierarchy. That is what I am trying to fill in. The GroupIdSource is being populated but the binding is not grabbing it at all.

<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"&gt;
      <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>

Here is my Full XAML to help out too. I have a . databinding working up above, but there is a difference in how its bound to my dataview. Its bound directly to the object then its child...you can see it in the first listbox for 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>
A: 

When binding against an XML data source, you should use XPath instead of Path to reach the desired element/attribute.

EDIT: You need to somehow set your object to be the datacontext of the control (or one of its ancestors) and then you can reference any property or nested property of it. For example in your case:

...{Binding Path=DoctorOfficesCollection[0].GroupIdSource.GroupName}...
Aviad P.
the actual element is not xml. I converted the structure of my object to xml just to help with understanding the layout of my object.
ecathell
Edited answer..
Aviad P.
ok well i have the itemsource of the Listbox set to {binding path=selecteddoctor.officecollection}is there someway I have to manipulate the individual listitems to know which instance of the collection object to get? I thought My NPI example was similar, but I remember that that table is actually a 1:1 relationship not a 1:many...
ecathell
A: 

I finally got this to behave after much reading. But in reality symantically nothing has changed in my code unless I am missing something in regards to how wpf controls work. I may slowly unwind these changes since its on a test view anyway and see if I can replicate the problem. Below is the working code for anyone who may be having a similar problem and needs to know how to do this.

<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>

as you can see really the only things I have done differnt is add a group box set to the original Databinding of the listbox by itself and then change itemsource to {bindings}. None of the other changes should have any real effect.

ecathell
Maybe the issynchronizedwithcurrentitem is the ticket. I dont think i had it at this level on my other view. But i will verify that.
ecathell