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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. WCF and WF
  4. Can I set a binding property of TextBox with Styles? [modified]

Can I set a binding property of TextBox with Styles? [modified]

Scheduled Pinned Locked Moved WCF and WF
wpfwcfquestion
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.
  • O Offline
    O Offline
    omid rezaei hanjani
    wrote on last edited by
    #1

    I have many TextBox that their Text property bind to model and this code is is repetetive: e.g. <TextBox x:Name="Title" Text="{Binding Model.Title , UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=true , ValidatesOnExceptions = true }"> </TextBox> Can I set 'UpdateSourceTrigger' , 'ValidatesOnDataErrors' and 'ValidatesOnExceptions' with using styles? How? thx

    modified on Monday, May 24, 2010 2:15 AM

    J 1 Reply Last reply
    0
    • O omid rezaei hanjani

      I have many TextBox that their Text property bind to model and this code is is repetetive: e.g. <TextBox x:Name="Title" Text="{Binding Model.Title , UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=true , ValidatesOnExceptions = true }"> </TextBox> Can I set 'UpdateSourceTrigger' , 'ValidatesOnDataErrors' and 'ValidatesOnExceptions' with using styles? How? thx

      modified on Monday, May 24, 2010 2:15 AM

      J Offline
      J Offline
      Jurgen Rohr
      wrote on last edited by
      #2

      Hi, yes, you can. And it's just as simple as you can imagine. Where you now write

      <TextBox
      ...
      Text="{Binding ...}" />

      make it into a style with

      <Style
      ...
      <Setter
      Property="Text"
      Value="{Binding ...}" />
      </Style>

      I just used "UpdateSourceTrigger" and it works; so why would the other binding-parameters refuse... Cheers Jürgen

      O 1 Reply Last reply
      0
      • J Jurgen Rohr

        Hi, yes, you can. And it's just as simple as you can imagine. Where you now write

        <TextBox
        ...
        Text="{Binding ...}" />

        make it into a style with

        <Style
        ...
        <Setter
        Property="Text"
        Value="{Binding ...}" />
        </Style>

        I just used "UpdateSourceTrigger" and it works; so why would the other binding-parameters refuse... Cheers Jürgen

        O Offline
        O Offline
        omid rezaei hanjani
        wrote on last edited by
        #3

        thanks but it doesn't work! because my binding value is different and just its configuration is the same. this is my code:

        <UserControl.Resources>
        <Style TargetType="TextBox">
        <Setter Property="MinWidth" Value="160" />
        </Style>
        </UserControl.Resources>

        ...

        <TextBox x:Name="Name" Text="{Binding Model.Name , UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=true , ValidatesOnExceptions = true }" />
        
        <TextBox x:Name="Title" Text="{Binding Model.Title , UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=true , ValidatesOnExceptions = true }" />
        
        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