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. Problem with this binding...

Problem with this binding...

Scheduled Pinned Locked Moved WPF
helpcsharpdatabasewpfwcf
3 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.
  • S Offline
    S Offline
    SledgeHammer01
    wrote on last edited by
    #1

    I have a style defined for a ListViewItem. In this style, there is a MultiDataTrigger. One of the conditions uses RelativeSource to get to a property in the ListView (RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListView}). The trigger is working correctly, just as I expect, so I know all the syntax and everything is defined correctly. HOWEVER, when you scroll a ListView and the ListViewItem goes off screen, it gets removed from the visual tree. This results in a lot of errors: System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='ListView', AncestorLevel='1''. BindingExpression:Path=SomeDP; DataItem=null; target element is 'ListViewItem' (Name=''); target property is 'NoTarget' (type 'Object') I've tried everything I know of to get rid of them: 1) Tried adding a FallbackValue to the binding. This solves the error messages on XP, but does not work on Windows 7??? .NET 4.0 on both OSes. 2) Tried running the value through a dummy converter. This has gotten rid of error messages in the past, but not this time. 3) Tried setting the PresentationTraceSources.TraceLevel="None" AP on the condition. No effect. Any other way to solve this?

    A 1 Reply Last reply
    0
    • S SledgeHammer01

      I have a style defined for a ListViewItem. In this style, there is a MultiDataTrigger. One of the conditions uses RelativeSource to get to a property in the ListView (RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=ListView}). The trigger is working correctly, just as I expect, so I know all the syntax and everything is defined correctly. HOWEVER, when you scroll a ListView and the ListViewItem goes off screen, it gets removed from the visual tree. This results in a lot of errors: System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='ListView', AncestorLevel='1''. BindingExpression:Path=SomeDP; DataItem=null; target element is 'ListViewItem' (Name=''); target property is 'NoTarget' (type 'Object') I've tried everything I know of to get rid of them: 1) Tried adding a FallbackValue to the binding. This solves the error messages on XP, but does not work on Windows 7??? .NET 4.0 on both OSes. 2) Tried running the value through a dummy converter. This has gotten rid of error messages in the past, but not this time. 3) Tried setting the PresentationTraceSources.TraceLevel="None" AP on the condition. No effect. Any other way to solve this?

      A Offline
      A Offline
      Adrian Cole
      wrote on last edited by
      #2

      I believe that a ListView uses a VirtualizingStackPanel for it's ItemsPanel and that the IsVirtualizing property defaults to true. Try setting it to false if you don't need your listview to hold many items. Either that or try using a regular StackPanel for the ItemsPanel.

      while (e) { Coyote(); }

      S 1 Reply Last reply
      0
      • A Adrian Cole

        I believe that a ListView uses a VirtualizingStackPanel for it's ItemsPanel and that the IsVirtualizing property defaults to true. Try setting it to false if you don't need your listview to hold many items. Either that or try using a regular StackPanel for the ItemsPanel.

        while (e) { Coyote(); }

        S Offline
        S Offline
        SledgeHammer01
        wrote on last edited by
        #3

        Definitely don't want to turn off virtualization. That eats a lot of memory. If I have 200 items, it adds around 50MB.

        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