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. WPF
  4. ListView SelectedValue Binding issue

ListView SelectedValue Binding issue

Scheduled Pinned Locked Moved WPF
helpquestioncsharpcsswpf
4 Posts 2 Posters 0 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.
  • B Offline
    B Offline
    bonkers123
    wrote on last edited by
    #1

    Hi all, I have a simple listview that has a currently selected item binding as follow:

    <ListView HorizontalAlignment="Left" Width="300" Name="ServiceListView" SelectionChanged="ServiceListView_SelectionChanged" SelectedValue="{Binding CurrentlySelectedService}" Grid.Row="0" Grid.RowSpan="2" Grid.Column="0">
    <ListView.View>
    <GridView>
    <GridViewColumn Header="Machine">
    <GridViewColumn.CellTemplate>
    <DataTemplate>
    <Label x:Name="ServiceNames" Content="{Binding ServiceController.MachineName}" />
    </DataTemplate>
    </GridViewColumn.CellTemplate>
    </GridViewColumn>
    <GridViewColumn Header="Service Names">
    <GridViewColumn.CellTemplate>
    <DataTemplate>
    <Label x:Name="ServiceNames" Content="{Binding ServiceController.ServiceName}" />
    </DataTemplate>
    </GridViewColumn.CellTemplate>
    </GridViewColumn>
    <GridViewColumn Header="Service status">
    <GridViewColumn.CellTemplate>
    <DataTemplate>
    <Label Width="80" x:Name="ServiceStatus" Content="{Binding ServiceController.CurrentStatus}" Background="{Binding ServiceController.ServiceStatusColour}" />
    </DataTemplate>
    </GridViewColumn.CellTemplate>
    </GridViewColumn>
    </GridView>
    </ListView.View>
    </ListView>

    And obviously in the constructor I do the following to enable bindings:

    DataContext = this;

    The problem: The binding to SelectedValue="{Binding CurrentlySelectedService}" works 100% (well, sort of). In my DEV environment it works 100% and the currently selected item works 100%. But for some or other reason when I deploy this to a Windows server 2003 box (with .Net 3.5 installed), the binding doesn't work anymore... How can I debug this issue? Has anyone experienced this problem before? This is not my first time experiencing this problem. I've seen this a few times now, but it seems to be very PC specific. It will work 100% on one pc, and then completely FAILS on another. Any help would be much appreciated.

    P 1 Reply Last reply
    0
    • B bonkers123

      Hi all, I have a simple listview that has a currently selected item binding as follow:

      <ListView HorizontalAlignment="Left" Width="300" Name="ServiceListView" SelectionChanged="ServiceListView_SelectionChanged" SelectedValue="{Binding CurrentlySelectedService}" Grid.Row="0" Grid.RowSpan="2" Grid.Column="0">
      <ListView.View>
      <GridView>
      <GridViewColumn Header="Machine">
      <GridViewColumn.CellTemplate>
      <DataTemplate>
      <Label x:Name="ServiceNames" Content="{Binding ServiceController.MachineName}" />
      </DataTemplate>
      </GridViewColumn.CellTemplate>
      </GridViewColumn>
      <GridViewColumn Header="Service Names">
      <GridViewColumn.CellTemplate>
      <DataTemplate>
      <Label x:Name="ServiceNames" Content="{Binding ServiceController.ServiceName}" />
      </DataTemplate>
      </GridViewColumn.CellTemplate>
      </GridViewColumn>
      <GridViewColumn Header="Service status">
      <GridViewColumn.CellTemplate>
      <DataTemplate>
      <Label Width="80" x:Name="ServiceStatus" Content="{Binding ServiceController.CurrentStatus}" Background="{Binding ServiceController.ServiceStatusColour}" />
      </DataTemplate>
      </GridViewColumn.CellTemplate>
      </GridViewColumn>
      </GridView>
      </ListView.View>
      </ListView>

      And obviously in the constructor I do the following to enable bindings:

      DataContext = this;

      The problem: The binding to SelectedValue="{Binding CurrentlySelectedService}" works 100% (well, sort of). In my DEV environment it works 100% and the currently selected item works 100%. But for some or other reason when I deploy this to a Windows server 2003 box (with .Net 3.5 installed), the binding doesn't work anymore... How can I debug this issue? Has anyone experienced this problem before? This is not my first time experiencing this problem. I've seen this a few times now, but it seems to be very PC specific. It will work 100% on one pc, and then completely FAILS on another. Any help would be much appreciated.

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

      You need Snoop[^] - run it on the target machine, and see what your listview thinks the DataContext is.

      "WPF has many lovers. It's a veritable porn star!" - Josh Smith

      As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

      My blog | My articles | MoXAML PowerToys | Onyx

      B 1 Reply Last reply
      0
      • P Pete OHanlon

        You need Snoop[^] - run it on the target machine, and see what your listview thinks the DataContext is.

        "WPF has many lovers. It's a veritable porn star!" - Josh Smith

        As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

        My blog | My articles | MoXAML PowerToys | Onyx

        B Offline
        B Offline
        bonkers123
        wrote on last edited by
        #3

        Got snoop ... didn't think of using it. Why the DataContext ? If the DataContext is not the correct one, how does one go about setting the correct one ...?

        P 1 Reply Last reply
        0
        • B bonkers123

          Got snoop ... didn't think of using it. Why the DataContext ? If the DataContext is not the correct one, how does one go about setting the correct one ...?

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

          The reason I suggested this, is that it sounds like the DataContext is behaving differently between the two machines. Snoop can be used to help you determine if this is the case.

          "WPF has many lovers. It's a veritable porn star!" - Josh Smith

          As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.

          My blog | My articles | MoXAML PowerToys | Onyx

          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