Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WCF and WF
  4. ListBox Bound DataTemplate Shows Up Blank

ListBox Bound DataTemplate Shows Up Blank

Scheduled Pinned Locked Moved WCF and WF
wpfwcfcomxmlquestion
4 Posts 2 Posters 3 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RNEELY
    wrote on last edited by
    #1

    Folks, I've been staring at this for hours and am missing something simple. Items in the first list box show up fine. However, I need to use a DataTemplate because the items in my real app are much more complex. Three items show up in the second listbox but they are all blank. Any ideas? <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Page1"> <Page.Resources> <XmlDataProvider x:Key="SetProvider" XPath="SetNums"> <x:XData> <SetNums xmlns=""> <SetNum>0</SetNum> <SetNum>1</SetNum> <SetNum>2</SetNum> </SetNums> </x:XData> </XmlDataProvider> <DataTemplate x:Key="SetTemplate"> <Label Content="{Binding XPath=SetNum}"/> </DataTemplate> </Page.Resources> <StackPanel Orientation="Horizontal"> <ListBox x:Name="lstWorks" ItemsSource="{Binding Source={StaticResource SetProvider}, XPath=SetNum}"> </ListBox> <ListBox x:Name="lstDoesNotWorkWhyDoItemsAppearBlank" ItemTemplate="{StaticResource SetTemplate}" ItemsSource="{Binding Source={StaticResource SetProvider}, XPath=SetNum}"> </ListBox> </StackPanel> </Page>

    Sincerely, -Ron

    P 1 Reply Last reply
    0
    • R RNEELY

      Folks, I've been staring at this for hours and am missing something simple. Items in the first list box show up fine. However, I need to use a DataTemplate because the items in my real app are much more complex. Three items show up in the second listbox but they are all blank. Any ideas? <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Page1"> <Page.Resources> <XmlDataProvider x:Key="SetProvider" XPath="SetNums"> <x:XData> <SetNums xmlns=""> <SetNum>0</SetNum> <SetNum>1</SetNum> <SetNum>2</SetNum> </SetNums> </x:XData> </XmlDataProvider> <DataTemplate x:Key="SetTemplate"> <Label Content="{Binding XPath=SetNum}"/> </DataTemplate> </Page.Resources> <StackPanel Orientation="Horizontal"> <ListBox x:Name="lstWorks" ItemsSource="{Binding Source={StaticResource SetProvider}, XPath=SetNum}"> </ListBox> <ListBox x:Name="lstDoesNotWorkWhyDoItemsAppearBlank" ItemTemplate="{StaticResource SetTemplate}" ItemsSource="{Binding Source={StaticResource SetProvider}, XPath=SetNum}"> </ListBox> </StackPanel> </Page>

      Sincerely, -Ron

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      Ron - change this line:

      <Label Content="{Binding XPath=SetNum}"/>

      to

      <Label Content="{Binding}"/>

      That ought to do it.

      Deja View - the feeling that you've seen this post before.

      My blog | My articles

      R 1 Reply Last reply
      0
      • P Pete OHanlon

        Ron - change this line:

        <Label Content="{Binding XPath=SetNum}"/>

        to

        <Label Content="{Binding}"/>

        That ought to do it.

        Deja View - the feeling that you've seen this post before.

        My blog | My articles

        R Offline
        R Offline
        RNEELY
        wrote on last edited by
        #3

        Thanks Pete. That did it. Upon reflection, the binding already included XPath so it did not need to be in the data template.

        Sincerely, -Ron

        P 1 Reply Last reply
        0
        • R RNEELY

          Thanks Pete. That did it. Upon reflection, the binding already included XPath so it did not need to be in the data template.

          Sincerely, -Ron

          P Offline
          P Offline
          Pete OHanlon
          wrote on last edited by
          #4

          :-D I know - it's always something simple like that, that keeps you hunting about for hours.

          Deja View - the feeling that you've seen this post before.

          My blog | My articles

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups