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. Unable to bind StoryBoard to a label

Unable to bind StoryBoard to a label

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

    Hi, I'm facing a problem to bind a StoryBoard to a label in my WPF application. My XAML lloks like this:

        <Label Height="28" Margin="308,27,250,0" Name="PostingStatusLabel" VerticalAlignment="Top" HorizontalContentAlignment="Left" Foreground="ForestGreen" FontWeight="bold">
            
            </Label.Triggers>
        </Label>
    

    When I'm trying to run this application.I get XAMLParseExeption at the start of Label.Triggers tag. Anyone? Best regards, Eli

    P 1 Reply Last reply
    0
    • E eli15021979

      Hi, I'm facing a problem to bind a StoryBoard to a label in my WPF application. My XAML lloks like this:

          <Label Height="28" Margin="308,27,250,0" Name="PostingStatusLabel" VerticalAlignment="Top" HorizontalContentAlignment="Left" Foreground="ForestGreen" FontWeight="bold">
              
              </Label.Triggers>
          </Label>
      

      When I'm trying to run this application.I get XAMLParseExeption at the start of Label.Triggers tag. Anyone? Best regards, Eli

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

      You're getting this exception because it's expecting an Event Trigger here, not a data trigger. If you want to use a DataTrigger, you have to apply it to a Style, ControlTemplate or DataTemplate. If I were you, I would create a style something like this:

      <Style x:Key="LabelStyle1" TargetType="{x:Type Label}">
      <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
      <Setter Property="Background" Value="Transparent"/>
      <Setter Property="Padding" Value="5"/>
      <Setter Property="HorizontalContentAlignment" Value="Left"/>
      <Setter Property="VerticalContentAlignment" Value="Top"/>
      <Setter Property="Template">
      <Setter.Value>
      <ControlTemplate TargetType="{x:Type Label}">
      <ControlTemplate.Resources>
      <Storyboard x:Key="Storyboard1">
      <ObjectAnimationUsingKeyFrames
      Storyboard.TargetProperty="(ContentControl.Content)" Storyboard.TargetName="contentPresenter"
      RepeatBehavior="Forever" FillBehavior="HoldEnd">
      <DiscreteObjectKeyFrame KeyTime="0:0:0.3" Value="Posting."/>
      <DiscreteObjectKeyFrame KeyTime="0:0:0.6" Value="Posting.."/>
      <DiscreteObjectKeyFrame KeyTime="0:0:0.9" Value="Posting.."/>
      <DiscreteObjectKeyFrame KeyTime="0:0:1.2" Value="Posting..."/>
      <DiscreteObjectKeyFrame KeyTime="0:0:1.5" Value="Posting...."/>
      <DiscreteObjectKeyFrame KeyTime="0:0:1.8" Value="Posting....."/>
      </ObjectAnimationUsingKeyFrames>
      </Storyboard>
      </ControlTemplate.Resources>
      <Border BorderBrush="{TemplateBinding BorderBrush}"
      BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}"
      Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true">
      <ContentPresenter x:Name="contentPresenter"
      HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
      RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
      VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
      </Border>
      <ControlTemplate.Triggers>
      <DataTrigger Binding="{Binding IsPendingPostExist}" Value="True">
      <DataTrigger.EnterActions>
      <BeginStoryboard Sto

      E 1 Reply Last reply
      0
      • P Pete OHanlon

        You're getting this exception because it's expecting an Event Trigger here, not a data trigger. If you want to use a DataTrigger, you have to apply it to a Style, ControlTemplate or DataTemplate. If I were you, I would create a style something like this:

        <Style x:Key="LabelStyle1" TargetType="{x:Type Label}">
        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="Padding" Value="5"/>
        <Setter Property="HorizontalContentAlignment" Value="Left"/>
        <Setter Property="VerticalContentAlignment" Value="Top"/>
        <Setter Property="Template">
        <Setter.Value>
        <ControlTemplate TargetType="{x:Type Label}">
        <ControlTemplate.Resources>
        <Storyboard x:Key="Storyboard1">
        <ObjectAnimationUsingKeyFrames
        Storyboard.TargetProperty="(ContentControl.Content)" Storyboard.TargetName="contentPresenter"
        RepeatBehavior="Forever" FillBehavior="HoldEnd">
        <DiscreteObjectKeyFrame KeyTime="0:0:0.3" Value="Posting."/>
        <DiscreteObjectKeyFrame KeyTime="0:0:0.6" Value="Posting.."/>
        <DiscreteObjectKeyFrame KeyTime="0:0:0.9" Value="Posting.."/>
        <DiscreteObjectKeyFrame KeyTime="0:0:1.2" Value="Posting..."/>
        <DiscreteObjectKeyFrame KeyTime="0:0:1.5" Value="Posting...."/>
        <DiscreteObjectKeyFrame KeyTime="0:0:1.8" Value="Posting....."/>
        </ObjectAnimationUsingKeyFrames>
        </Storyboard>
        </ControlTemplate.Resources>
        <Border BorderBrush="{TemplateBinding BorderBrush}"
        BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}"
        Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true">
        <ContentPresenter x:Name="contentPresenter"
        HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
        RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
        VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
        </Border>
        <ControlTemplate.Triggers>
        <DataTrigger Binding="{Binding IsPendingPostExist}" Value="True">
        <DataTrigger.EnterActions>
        <BeginStoryboard Sto

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

        Hi, Thanks,it is working... :laugh: I have one more question: I'm trying to stop the story board when the trigger is being changed from true to false. I've set the story board name,and trying to stop it like this:

        .
        .
        .

        but when the trigger switches to false,I receive the following InvalidOperationException: "Storyboard1 object Name found but it is not a BeginStoryboard object." Is there something I'm missing? Thanks again, Eli

        P 1 Reply Last reply
        0
        • E eli15021979

          Hi, Thanks,it is working... :laugh: I have one more question: I'm trying to stop the story board when the trigger is being changed from true to false. I've set the story board name,and trying to stop it like this:

          .
          .
          .

          but when the trigger switches to false,I receive the following InvalidOperationException: "Storyboard1 object Name found but it is not a BeginStoryboard object." Is there something I'm missing? Thanks again, Eli

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

          The reason is, you haven't named the storyboard part you think you have. The key here is that it's BeginStoryboardName - which tells you that you need to apply a name to BeginStoryboard. Add a name to BeginStoryboard, and then use this name in the StopStoryboard.

          Forgive your enemies - it messes with their heads

          "Mind bleach! Send me mind bleach!" - Nagy Vilmos

          My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

          E 1 Reply Last reply
          0
          • P Pete OHanlon

            The reason is, you haven't named the storyboard part you think you have. The key here is that it's BeginStoryboardName - which tells you that you need to apply a name to BeginStoryboard. Add a name to BeginStoryboard, and then use this name in the StopStoryboard.

            Forgive your enemies - it messes with their heads

            "Mind bleach! Send me mind bleach!" - Nagy Vilmos

            My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

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

            :doh: Beginners faults... Thanks a lot.. Best regards, Eli

            P 1 Reply Last reply
            0
            • E eli15021979

              :doh: Beginners faults... Thanks a lot.. Best regards, Eli

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

              No problem. This is what we're here for - to help.

              Forgive your enemies - it messes with their heads

              "Mind bleach! Send me mind bleach!" - Nagy Vilmos

              My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

              W 1 Reply Last reply
              0
              • P Pete OHanlon

                No problem. This is what we're here for - to help.

                Forgive your enemies - it messes with their heads

                "Mind bleach! Send me mind bleach!" - Nagy Vilmos

                My blog | My articles | MoXAML PowerToys | Mole 2010 - debugging made easier - my favourite utility

                W Offline
                W Offline
                Wayne Gaylard
                wrote on last edited by
                #7

                +5 for patience and persistence :laugh:

                When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman

                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