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. Bind TextBlock.Text in a Style by DataTrigger [modified]

Bind TextBlock.Text in a Style by DataTrigger [modified]

Scheduled Pinned Locked Moved WCF and WF
wpfwcfhelp
5 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! Anyone please can help me with this:

    <Style TargetType="{x:Type Button}">
    <Setter Property="Background" Value="Red"/>
    <Style.Triggers>
    <DataTrigger Binding="{Binding Path=IsDevice}" Value="True">
    <Setter Property="Template">
    <Setter.Value>
    <ControlTemplate>
    <StackPanel>
    <TextBlock x:Name="txt"></TextBlock>
    <StackPanel.Style>
    <Style>
    <Style.Triggers>
    <DataTrigger Binding="{Binding Path=PositionDevice}" Value="0">

    // HERE I WOULD NEED SOMETHING LIKE THIS:
    <Setter Property="{Binding Path=Text, ElementName=txt}" Value="TEST"/>
    //WHICH IS NOT WORKING

                                                                      </DataTrigger>
    

    Thank you in advance!

    modified on Sunday, September 13, 2009 6:42 PM

    G 1 Reply Last reply
    0
    • E ezazazel

      Hi folks! Anyone please can help me with this:

      <Style TargetType="{x:Type Button}">
      <Setter Property="Background" Value="Red"/>
      <Style.Triggers>
      <DataTrigger Binding="{Binding Path=IsDevice}" Value="True">
      <Setter Property="Template">
      <Setter.Value>
      <ControlTemplate>
      <StackPanel>
      <TextBlock x:Name="txt"></TextBlock>
      <StackPanel.Style>
      <Style>
      <Style.Triggers>
      <DataTrigger Binding="{Binding Path=PositionDevice}" Value="0">

      // HERE I WOULD NEED SOMETHING LIKE THIS:
      <Setter Property="{Binding Path=Text, ElementName=txt}" Value="TEST"/>
      //WHICH IS NOT WORKING

                                                                        </DataTrigger>
      

      Thank you in advance!

      modified on Sunday, September 13, 2009 6:42 PM

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

      I believe you are looking for the TargetName property of the Setter.

      <Setter TargetName="txt" Property="Text" Value="TEST" />

      E 1 Reply Last reply
      0
      • G Gideon Engelberth

        I believe you are looking for the TargetName property of the Setter.

        <Setter TargetName="txt" Property="Text" Value="TEST" />

        E Offline
        E Offline
        ezazazel
        wrote on last edited by
        #3

        Error 1 TargetName property cannot be set on a Style Setter Thank you for your hint, unfortunately it's not working. Any other ideas maybe?

        G 1 Reply Last reply
        0
        • E ezazazel

          Error 1 TargetName property cannot be set on a Style Setter Thank you for your hint, unfortunately it's not working. Any other ideas maybe?

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

          Since the trigger does not seem like it really needs to be inside the style (from what I can see here), I would suggest moving the trigger into the ControlTemplate's trigger collection instead.

          E 1 Reply Last reply
          0
          • G Gideon Engelberth

            Since the trigger does not seem like it really needs to be inside the style (from what I can see here), I would suggest moving the trigger into the ControlTemplate's trigger collection instead.

            E Offline
            E Offline
            ezazazel
            wrote on last edited by
            #5

            Thanks! That did it!

            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