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. Databinding and Value Converter questions

Databinding and Value Converter questions

Scheduled Pinned Locked Moved WPF
wpfhelptutorialquestioncsharp
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.
  • M Offline
    M Offline
    Michael Eber
    wrote on last edited by
    #1

    OKAY -- I've done a ton of searching and I've not found anything that can directly help me with what I need to do. I'm building a business application with Silverlight 3.0 and I'm down to my VERY LAST issue! I have 3 ComboBox controls (building, datacenter, locationType) where datacenter has a dependancy on building. I have a listbox with customers (works great). When a customer is selected, a list of existing locations is populated. (works great) For these (and other) populated controls, I put out a message "loading...blah blah blah" then when the data comes back I display "data loaded...blah blah blah" which works great. I've got my datacenter dependancy working great as well. Pick a building and the correct set of datacenters is loaded. My editor fields are wrapped in a grid and a datasource for my location object was created. I populate it in my code by setting editorContainer.DataContext = selectedCustomerLocation; editorContainer is the grid that wraps all of my editor controls. Each control that edits the fields of the control is bound to the datacontext of the grid, but Expression does not seem to place the parent object name as a fully-qualified name. (example my xaml says 'BuildingNumber' instead of CustomerLocation.BuildingNumber) I expected the editor controls to self populate with the data once DataContext was set. (doesn't work) I also want each combobox to display the correct selected item. I know I need to say SelectedText = "{Binding {fieldName} Converter=myValueConverter, ConverterParameter= ....". I also expected that in the Convert logic I perform the linq to lookup the building enumerated object and return the text value for the integer returned in the customer location object. Not quite sure how to explicitely pass to the converter the value of the building ID (for example) AND the list of building name/values to have it return the correct text. So this is the first question which is the syntax to pass parameters into the converter? The second question, then, is Expression put the datacontext in a self-contained location within the grid followed by my fields. Do I have to extend the end tag to wrap my editor controls? Or is DataContext all wrong? I think I saw one guy use Data Template??? Any help at all would be great. I found a ton of examples but all of them are either too simplistic (working with internal collections statically created and never dealing with an externally selected object to bind with) or buried within the context of a

    A 1 Reply Last reply
    0
    • M Michael Eber

      OKAY -- I've done a ton of searching and I've not found anything that can directly help me with what I need to do. I'm building a business application with Silverlight 3.0 and I'm down to my VERY LAST issue! I have 3 ComboBox controls (building, datacenter, locationType) where datacenter has a dependancy on building. I have a listbox with customers (works great). When a customer is selected, a list of existing locations is populated. (works great) For these (and other) populated controls, I put out a message "loading...blah blah blah" then when the data comes back I display "data loaded...blah blah blah" which works great. I've got my datacenter dependancy working great as well. Pick a building and the correct set of datacenters is loaded. My editor fields are wrapped in a grid and a datasource for my location object was created. I populate it in my code by setting editorContainer.DataContext = selectedCustomerLocation; editorContainer is the grid that wraps all of my editor controls. Each control that edits the fields of the control is bound to the datacontext of the grid, but Expression does not seem to place the parent object name as a fully-qualified name. (example my xaml says 'BuildingNumber' instead of CustomerLocation.BuildingNumber) I expected the editor controls to self populate with the data once DataContext was set. (doesn't work) I also want each combobox to display the correct selected item. I know I need to say SelectedText = "{Binding {fieldName} Converter=myValueConverter, ConverterParameter= ....". I also expected that in the Convert logic I perform the linq to lookup the building enumerated object and return the text value for the integer returned in the customer location object. Not quite sure how to explicitely pass to the converter the value of the building ID (for example) AND the list of building name/values to have it return the correct text. So this is the first question which is the syntax to pass parameters into the converter? The second question, then, is Expression put the datacontext in a self-contained location within the grid followed by my fields. Do I have to extend the end tag to wrap my editor controls? Or is DataContext all wrong? I think I saw one guy use Data Template??? Any help at all would be great. I found a ton of examples but all of them are either too simplistic (working with internal collections statically created and never dealing with an externally selected object to bind with) or buried within the context of a

      A Offline
      A Offline
      Abhinav S
      wrote on last edited by
      #2

      Michael Eber wrote:

      SelectedText = "{Binding {fieldName} Converter=myValueConverter, ConverterParameter=

      A trick I used to pass multple values (my entire collection) to the converter was to not bind to the field name. Try this - SelectedText = "{Binding Converter=myValueConverter, ConverterParameter= ....".

      Michael Eber wrote:

      The second question, then, is Expression put the datacontext in a self-contained location within the grid followed by my fields. Do I have to extend the end tag to wrap my editor controls? Or is DataContext all wrong? I think I saw one guy use Data Template???

      Not quite sure I understand your question. However, IMO, the datacontext looks fine. DataTemplates are used to specify the visual structure of a data object, so DataContexts and DataTemplates are actually two different things (used differently).

      There are only 10 types of people in this world — those who understand binary, and those who don't.

      M 1 Reply Last reply
      0
      • A Abhinav S

        Michael Eber wrote:

        SelectedText = "{Binding {fieldName} Converter=myValueConverter, ConverterParameter=

        A trick I used to pass multple values (my entire collection) to the converter was to not bind to the field name. Try this - SelectedText = "{Binding Converter=myValueConverter, ConverterParameter= ....".

        Michael Eber wrote:

        The second question, then, is Expression put the datacontext in a self-contained location within the grid followed by my fields. Do I have to extend the end tag to wrap my editor controls? Or is DataContext all wrong? I think I saw one guy use Data Template???

        Not quite sure I understand your question. However, IMO, the datacontext looks fine. DataTemplates are used to specify the visual structure of a data object, so DataContexts and DataTemplates are actually two different things (used differently).

        There are only 10 types of people in this world — those who understand binary, and those who don't.

        M Offline
        M Offline
        Michael Eber
        wrote on last edited by
        #3

        What I mean as far as passing data to the converter is this: I need to pass the collection of objects that populate the dropdown box. I also need to pass the value set by the object. I've seen a setup like this for passing a date: ConvertParameter=0\d\ But I have no idea what that means or how they are actually passing the date field.

        A 1 Reply Last reply
        0
        • M Michael Eber

          What I mean as far as passing data to the converter is this: I need to pass the collection of objects that populate the dropdown box. I also need to pass the value set by the object. I've seen a setup like this for passing a date: ConvertParameter=0\d\ But I have no idea what that means or how they are actually passing the date field.

          A Offline
          A Offline
          Abhinav S
          wrote on last edited by
          #4

          Michael Eber wrote:

          ConvertParameter=0\d

          AFAIK, ConvertParameter does not support binding. So, you can only pass 'hardcoded' values like 0\d, which will format your date. The date is passed using the binding value e.g. Text="{Binding myDate, Converter={StaticResource myConverter}}". However, the entire collection can be passed into the converter. The appropriate value(s) can then be used inside the converter to construct the value you want to display in your UI.

          There are only 10 types of people in this world — those who understand binary, and those who don't.

          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