Unable to bind StoryBoard to a label
-
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
-
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
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 -
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 StoHi, 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
-
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
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 toBeginStoryboard
. Add a name toBeginStoryboard
, and then use this name in theStopStoryboard
.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
-
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 toBeginStoryboard
. Add a name toBeginStoryboard
, and then use this name in theStopStoryboard
.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
:doh: Beginners faults... Thanks a lot.. Best regards, Eli
-
:doh: Beginners faults... Thanks a lot.. Best regards, Eli
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
-
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
+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