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. ValidationRule bind two values

ValidationRule bind two values

Scheduled Pinned Locked Moved WPF
helpdatabasewpfwcfregex
2 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.
  • E Offline
    E Offline
    ezazazel
    wrote on last edited by
    #1

    Hi folks! Can anyone please help me with this: I have two values (one manual input and one from a database) and I need to compare them/ validate them via ValidationRules and show errors if they do not match. LOGIC: V1 == V2 => OK V1 != V2 => NOK, Error

    <TextBlock>
    <TextBlock.Text>
    <Binding ...>
    <Binding.ValidationRules>
    <localValidation:ValidateIt V1={Binding Path=...} V2={Binding Path=}/>
    </Binding.ValidationRules/>
    <TextBlock.Text/>
    </TextBlock>

    where

    public class ValidateIt : ValidationRule
    public int V1 {get;set;}
    public int V2 {get;set;}

    Unfortunately it tells me, that V1 and V2 cannot be bound due to the fact, that these are no DependencyProperties. I'm stuck... Thanks in advance, eza

    P 1 Reply Last reply
    0
    • E ezazazel

      Hi folks! Can anyone please help me with this: I have two values (one manual input and one from a database) and I need to compare them/ validate them via ValidationRules and show errors if they do not match. LOGIC: V1 == V2 => OK V1 != V2 => NOK, Error

      <TextBlock>
      <TextBlock.Text>
      <Binding ...>
      <Binding.ValidationRules>
      <localValidation:ValidateIt V1={Binding Path=...} V2={Binding Path=}/>
      </Binding.ValidationRules/>
      <TextBlock.Text/>
      </TextBlock>

      where

      public class ValidateIt : ValidationRule
      public int V1 {get;set;}
      public int V2 {get;set;}

      Unfortunately it tells me, that V1 and V2 cannot be bound due to the fact, that these are no DependencyProperties. I'm stuck... Thanks in advance, eza

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

      They don't need to be DependencyPropety's to be bound. There's a lightweight way of achieving what you want using POCO's. If you take a look at my sample here[^], you'll see that I'm handling the validation based on a ViewModel, which is totally none-DP based.

      "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