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. How to force- invalidate the DataContext of a control ?

How to force- invalidate the DataContext of a control ?

Scheduled Pinned Locked Moved WCF and WF
wpfquestionwcftutorial
3 Posts 3 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.
  • M Offline
    M Offline
    Moim Hossain
    wrote on last edited by
    #1

    Basically, I have a TreeView and a ListView. When users changes the selection of TreeNode then, I updated the Listview with some relevant data to that selected TreeNode. But I am using a converter here to populate the data for the ListView. The binding xaml of the ListView is as follows <listbox x:name="datagrid" datacontext="{Binding Path=SelectedValue, Converter={StaticResource DocumentConverter}, ElementName=myTree}" xmlns:x="#unknown"></listbox> Now, I have a button at some where into the same window, and I want when user will click onto that button, ListBox data should be refreshed. Basically the logic of the converter does something different when a button has been clicked. So, if somehow i was able to re-execute the converter code that would be great. In short, I need to invalidate the DataContext of the ListBox when the button gets clicked. How can i do that? Thanks in advance!

    Moim Hossain Senior Software Engineer KAZ Software

    C 1 Reply Last reply
    0
    • M Moim Hossain

      Basically, I have a TreeView and a ListView. When users changes the selection of TreeNode then, I updated the Listview with some relevant data to that selected TreeNode. But I am using a converter here to populate the data for the ListView. The binding xaml of the ListView is as follows <listbox x:name="datagrid" datacontext="{Binding Path=SelectedValue, Converter={StaticResource DocumentConverter}, ElementName=myTree}" xmlns:x="#unknown"></listbox> Now, I have a button at some where into the same window, and I want when user will click onto that button, ListBox data should be refreshed. Basically the logic of the converter does something different when a button has been clicked. So, if somehow i was able to re-execute the converter code that would be great. In short, I need to invalidate the DataContext of the ListBox when the button gets clicked. How can i do that? Thanks in advance!

      Moim Hossain Senior Software Engineer KAZ Software

      C Offline
      C Offline
      Colin Eberhardt
      wrote on last edited by
      #2

      Hi, The quick and dirty way is to set the DataContext to null then set it back to its original source. This should force an update. Colin E.

      B 1 Reply Last reply
      0
      • C Colin Eberhardt

        Hi, The quick and dirty way is to set the DataContext to null then set it back to its original source. This should force an update. Colin E.

        B Offline
        B Offline
        Brian Griggs
        wrote on last edited by
        #3

        You could also try using the BindingExpression class in your button's click event handler:

        BindingExpression expression = BindingOperations.GetBindingExpression(listBox, ListBox.DataContextProperty);
        expression.UpdateTarget();

        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