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. Best Way To Convert A Value Based On The Type In A Different Control

Best Way To Convert A Value Based On The Type In A Different Control

Scheduled Pinned Locked Moved WCF and WF
tutorialquestiondatabasehelp
4 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.
  • B Offline
    B Offline
    BlitzPackage
    wrote on last edited by
    #1

    Good People, I have a control that records the amount of time of a specific event - which the user enters.   However, the user can also choose the type of time span.   For example, in the duration they can enter the number '5'.   Then, they can select the type of time span as "Days", "Hours", or "Minutes". In order to facilitate comparisons, I have to convert all of the entries to minutes when it is written to the database; then convert them back to the chosen time span type when I must display it to the user. My question is: what's the best way to do this?   I thought about using a value converter, however I don't know how to make a value converter grab the type selected in a different control.   Plus, I have problems with value converters because I don't know how to make it wait until the user finishes typing if they are entering more than one character. Any help you can provide would be greatly appreciate. Thanks. Blitz

    M G 2 Replies Last reply
    0
    • B BlitzPackage

      Good People, I have a control that records the amount of time of a specific event - which the user enters.   However, the user can also choose the type of time span.   For example, in the duration they can enter the number '5'.   Then, they can select the type of time span as "Days", "Hours", or "Minutes". In order to facilitate comparisons, I have to convert all of the entries to minutes when it is written to the database; then convert them back to the chosen time span type when I must display it to the user. My question is: what's the best way to do this?   I thought about using a value converter, however I don't know how to make a value converter grab the type selected in a different control.   Plus, I have problems with value converters because I don't know how to make it wait until the user finishes typing if they are entering more than one character. Any help you can provide would be greatly appreciate. Thanks. Blitz

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      BlitzPackage wrote:

      I don't know how to make it wait until the user finishes typing if they are entering more than one character.

      By default, the Text property on TextBox controls doesn't update the source until the control loses focus, specifically for this reason. (if you find this is NOT the default, you can set the UpdateSourceTrigger to LostFocus on the binding)

      BlitzPackage wrote:

      I thought about using a value converter, however I don't know how to make a value converter grab the type selected in a different control.

      Converters can take a converter parameter, but unfortunately you can't use a binding in XAML to pass that parameter value. If the time-span type selection controls are bound to a property in the same data object as the desired source property for the time span binding, then you could bind to the entire object instead of the single property. Then your converter would have access to the both the type and span properties in that data object. You could also bind to the DataContext of any element in the tree if there's a place to get the required properties from. Just using code on the textbox's LostFocus event would be relatively simple as well. The best way? I don't know :)

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      B 1 Reply Last reply
      0
      • M Mark Salsbery

        BlitzPackage wrote:

        I don't know how to make it wait until the user finishes typing if they are entering more than one character.

        By default, the Text property on TextBox controls doesn't update the source until the control loses focus, specifically for this reason. (if you find this is NOT the default, you can set the UpdateSourceTrigger to LostFocus on the binding)

        BlitzPackage wrote:

        I thought about using a value converter, however I don't know how to make a value converter grab the type selected in a different control.

        Converters can take a converter parameter, but unfortunately you can't use a binding in XAML to pass that parameter value. If the time-span type selection controls are bound to a property in the same data object as the desired source property for the time span binding, then you could bind to the entire object instead of the single property. Then your converter would have access to the both the type and span properties in that data object. You could also bind to the DataContext of any element in the tree if there's a place to get the required properties from. Just using code on the textbox's LostFocus event would be relatively simple as well. The best way? I don't know :)

        Mark Salsbery Microsoft MVP - Visual C++ :java:

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

        Thanks for your reply.   I will look into it. Blitz

        1 Reply Last reply
        0
        • B BlitzPackage

          Good People, I have a control that records the amount of time of a specific event - which the user enters.   However, the user can also choose the type of time span.   For example, in the duration they can enter the number '5'.   Then, they can select the type of time span as "Days", "Hours", or "Minutes". In order to facilitate comparisons, I have to convert all of the entries to minutes when it is written to the database; then convert them back to the chosen time span type when I must display it to the user. My question is: what's the best way to do this?   I thought about using a value converter, however I don't know how to make a value converter grab the type selected in a different control.   Plus, I have problems with value converters because I don't know how to make it wait until the user finishes typing if they are entering more than one character. Any help you can provide would be greatly appreciate. Thanks. Blitz

          G Offline
          G Offline
          Gideon Engelberth
          wrote on last edited by
          #4

          In that kind of situation, I would put a DependencyProperty on the value converter and bind that to the radio buttons. In this case, the property would probably be an enum TimeType or some such and the control used to select the units would be bound to the property on the converter. I do not know if changing the TimeType property on the converter will update the bound data property, so that may be something you will have to look into.

          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