RIck Mueller

RIck Mueller

  • NA
  • 47
  • 0

Page Binding vs MainWindow Binding

Aug 27 2010 2:28 AM

Hello
Currently I have a listbox in the mainwindow basic XML Databinding no issues. When I put the same Listbox on a page.xml, the image doesn't bind.
Here Is my code:
XML Data
 <Table>
   <CompanyName>Digital Kitchen1</CompanyName>
   <Location>Eden Prairie1</Location>
   <ContactName>Rick Mueller</ContactName>
   <ContactTitle>PrepCook</ContactTitle>
   <EmpImage>male.jpg</EmpImage>
   <StDate>15664</StDate>
   <EmpId>156</EmpId>
  </Table>

Here is my xaml
 xmlns:local="clr-namespace:Digital_Kitchen_CdrPrint" 
<local:ImageConverter x:Key="ImageConverter" />
<ListBox x:Name="EmployeeDataList"  ScrollViewer.VerticalScrollBarVisibility="Hidden" 
       ItemsSource="{Binding Source={StaticResource Employees}}"  SelectionChanged="RecBOX_SelectionChanged" BorderBrush="{x:Null}" Margin="-97.152,17.488,-20.787,51.345" RenderTransformOrigin="0.5,0.5" >
       <ListBox.RenderTransform>
        <TransformGroup>
         <ScaleTransform/>
         <SkewTransform/>
         <RotateTransform/>
         <TranslateTransform/>
        </TransformGroup>
       </ListBox.RenderTransform>
       <ListBox.GroupStyle>
        <GroupStyle ContainerStyle="{StaticResource ContainerStyle1}"/>
       </ListBox.GroupStyle>
       <ListBox.ItemTemplate>

 
        <DataTemplate>
      
         <Grid Height="69.333" Width="266" Margin="5" HorizontalAlignment="Left">
          <Grid.ColumnDefinitions>
           <ColumnDefinition Width="0.254*"/>
           <ColumnDefinition Width="0.746*"/>
          </Grid.ColumnDefinitions>
          <Image Source="{Binding XPath=EmpImage}" Stretch="Uniform"/>
          <StackPanel Grid.Column="3" Orientation="Horizontal" Margin="5,0,0,0">
                                     
           <StackPanel Margin="10,0,0,0">
            <TextBlock TextWrapping="Wrap" FontSize="18" Text="{Binding XPath=ContactName}"/>
            <TextBlock TextWrapping="Wrap" FontSize="14" Text="{Binding XPath=Location}"/>
            <TextBlock TextWrapping="Wrap" FontSize="14" Text="{Binding XPath=StDate}"/>
           </StackPanel>
          </StackPanel>
         </Grid>
         
      
 
        </DataTemplate>
    
       </ListBox.ItemTemplate>
       <ListBox.Background>
        <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
         <GradientStop Color="#00000000" Offset="0.435"/>
         <GradientStop Color="#00BDB5B5" Offset="1"/>
         <GradientStop Color="#008C8888" Offset="0.009"/>
        </LinearGradientBrush>
       </ListBox.Background>
      </ListBox>
     </Grid>
     <Grid Height="221.5" Canvas.Left="26.5" Canvas.Top="-56" Width="709.647" DataContext="{Binding SelectedItem, ElementName=EmployeeDataList}">
      <Image x:Name="image1" Source="{Binding XPath=EmpImage}" Margin="8,8,0,0" RenderTransformOrigin="0.5,0.5" Stretch="Fill" Height="97.858" VerticalAlignment="Top" HorizontalAlignment="Left" Width="101.056">
       <Image.Effect>
        <DropShadowEffect/>
       </Image.Effect>
        
      </Image>
      <StackPanel Margin="119.331,8,0,70.833" HorizontalAlignment="Left" Width="192">
       <TextBlock x:Name="NamText2"  Text="{Binding SelectedItem, Converter={StaticResource XmlValueConverter3}, ElementName=EmployeeDataList, Mode=OneWay}" TextWrapping="Wrap" FontSize="24" Margin="0,0,7.946,0" Height="37.655"/>
       <TextBlock Margin="0,0,92,0" TextWrapping="Wrap" FontSize="14" Text="{Binding XPath=ContactTitle}" Height="20.691"/>
       <TextBlock Height="18.691" TextWrapping="Wrap" FontSize="14" Text="{Binding XPath=Location}" Margin="0,0,92,0"/>
       <telerik:RadRating Height="19" Margin="0,0,84.452,0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" NumberOfItemsToGenerate="4"/>
       <TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" FontSize="14" Text="{Binding XPath=EmpId}" Width="48" Height="23.358"/>
      </StackPanel>
     </Grid>
 
Here is my XmlDataProvider
  <XmlDataProvider x:Key="Contact"
   Source="/Digital Kitchen CdrPrint;component/Database/Employee.xml"
   XPath="NewDataSet/Table"/>
  <CollectionViewSource x:Key="Employees"
   Source="{StaticResource Contact}">
   <CollectionViewSource.SortDescriptions>
     <scm:SortDescription PropertyName="ContactTitle" Direction="Ascending"/>
   </CollectionViewSource.SortDescriptions>
   <CollectionViewSource.GroupDescriptions>
     <PropertyGroupDescription PropertyName="ContactTitle"/>
   </CollectionViewSource.GroupDescriptions>
  </CollectionViewSource>

Again it works like a champ in the mainwindow xaml. But when its in the page xaml the image is the only element not binding..
I tried a ImageConverter
 
public
sealed class ImageConverter : IValueConverter
{
public object Convert(object value, Type targetType,
object parameter, CultureInfo culture)
{
try
{
return new BitmapImage(new Uri((string)value));
}
catch
{
return new BitmapImage();
}
}
public object ConvertBack(object value, Type targetType,
object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}

Any thoughts.