• 22.08.2025, 07:12
  • Registrieren
  • Anmelden
  • Sie sind nicht angemeldet.

 

zunder

Newbie

XAML - Blinkender Text

Mittwoch, 1. Januar 2025, 21:29

Hallo zusammen,
ein gutes neues Jahr wünsch ich allen
in der Überschrift "Wasserkreis" ist die Alarmfunktion in dem Text integriert, habe praktisch die Grafik aus dem Standard Alarm Status Element entfernt. Siehe Bild und Code
So weit alles gut.
Jetzt wollte ich doch zusätzlich bei Alarm ein Dauerblinken des Textes von Weiß nach Rot und bekomme es leider einfach nicht hin.
Kann da jemand helfen.
Vielen Dank
Grüße
Der zunder

Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<UserControl
   x:Name="this"
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
   xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
   xmlns:sys="clr-namespace:System;assembly=mscorlib"
   mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300">
   
	<UserControl.Resources>
    	<DataTemplate x:Key="TplNormal">
      	<TextBlock
        	Foreground="White"
        	Text="Wasserkreis" />
    	</DataTemplate>
    	<DataTemplate x:Key="TplWarning">
      	<TextBlock
        	Foreground="Orange"
        	Text="Wasserkreis" />
    	</DataTemplate>
    	<DataTemplate x:Key="TplAlarm">
      	<TextBlock
        	Foreground="Red"
        	Text="Wasserkreis" />
    	</DataTemplate>
    	<LinearGradientBrush
      	x:Key="BackgroundBrush" StartPoint="0,0" EndPoint="0,1">
        	<GradientStop Color="Black" Offset="0.7" />
        	<GradientStop Color="DimGray" Offset="0.0" />
    	</LinearGradientBrush>
	</UserControl.Resources>

	<Grid>
    	<Rectangle
      	Opacity="0.6"
      	RadiusX="2"
      	RadiusY="2"
      	StrokeThickness="1"
      	Fill="{StaticResource BackgroundBrush}"
      	Stroke="#FF2B2B2B" />
    	<ContentControl
      	FontFamily="Segoe UI"
      	FontWeight="Bold"
      	Width="Auto"
      	Height="Auto"
      	Margin="0,0,0,0"
      	FontSize="12"
      	HorizontalAlignment="Center"
      	VerticalAlignment="Center">
      	<ContentControl.Style>
        	<Style TargetType="ContentControl">
          	<Style.Triggers>
            	<DataTrigger Value="True" Binding="{Binding ElementName=this, Path=DataContext.Value, ConverterParameter=0, Converter={StaticResource CompareEqualConverter}}">
              	<Setter Property="ContentTemplate" Value="{StaticResource TplNormal}" />
            	</DataTrigger>
            	<DataTrigger Value="True" Binding="{Binding ElementName=this, Path=DataContext.Value, ConverterParameter=1, Converter={StaticResource CompareEqualConverter}}">
              	<Setter Property="ContentTemplate" Value="{StaticResource TplWarning}" />
            	</DataTrigger>
            	<DataTrigger Value="True" Binding="{Binding ElementName=this, Path=DataContext.Value, ConverterParameter=2, Converter={StaticResource CompareEqualConverter}}">
              	<Setter Property="ContentTemplate" Value="{StaticResource TplAlarm}" />
            	</DataTrigger>
          	</Style.Triggers>
        	</Style>
      	</ContentControl.Style>
    	</ContentControl>
	</Grid>
</UserControl>
»zunder« hat folgendes Bild angehängt:
  • Überschrift.png

zunder

Newbie

Donnerstag, 2. Januar 2025, 22:40

Einen schönen Abend,

Ich habe es nun mit dem Opacity aus der Standard Anzeige probiert. Das funktioniert auch sehr gut
siehe Code ganz unten

nun versuchte ich das mit den beiden Lösungsansätzen aus dem learn.microsoft.com innerhalb des Storyboard mit ColorAnimation zu lösen.

Das ging mächtig schief.

Mit den darunter stehenden Codes habe ich es geschafft die Aquasuite jedesmal so zu killen, das NUR eine komplette De-/Neuinstallation half! Zum Glück hatte ich eine Sicherung
Also vorsicht
<Storyboard BeginTime="00:00:00"
RepeatBehavior="Forever"
Storyboard.TargetName="txtBlockScannerText"
Storyboard.TargetProperty="(Foreground).(SolidColorBrush.Color)">
<ColorAnimation From="White" To="Red" Duration="0:0:1"/>
</Storyboard>


<Storyboard>
<ColorAnimation
Storyboard.TargetName="MySolidColorBrush"
Storyboard.TargetProperty="Color"
From="White" To="Red" Duration="0:0:1" />
</Storyboard>
Grüße
Zunder

Fogende mit Opacity funktioniert sehr gut

Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<UserControl
   x:Name="this"
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
   xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
   xmlns:sys="clr-namespace:System;assembly=mscorlib"
   mc:Ignorable="d"
   d:DesignHeight="300"
   d:DesignWidth="300">
   
	<UserControl.Resources>
    	<DataTemplate x:Key="TplNormal">
      	<TextBlock
        	Foreground="White"
        	Text="Wasserkreis" />
    	</DataTemplate>
    	<DataTemplate x:Key="TplWarning">
      	<TextBlock
        	Foreground="Orange"
        	Text="Wasserkreis" />
    	</DataTemplate>
    	<DataTemplate x:Key="TplAlarm">
      	<ContentControl>
        	<ContentControl.Style>
          	<Style TargetType="ContentControl">
            	<Style.Triggers>
              	<EventTrigger RoutedEvent="Loaded">
                	<BeginStoryboard>
                  	<Storyboard>
                    	<DoubleAnimation
                      	Storyboard.TargetProperty="Opacity"
                      	From="1.0" To="0.4" Duration="0:0:0.800"
                      	AutoReverse="True" RepeatBehavior="Forever" />
                  	</Storyboard>
                	</BeginStoryboard>
              	</EventTrigger>
            	</Style.Triggers>
          	</Style>
        	</ContentControl.Style>
        	<TextBlock
          	Foreground="Red"
          	Text="Wasserkreis" />
      	</ContentControl>
    	</DataTemplate>
    	<LinearGradientBrush
      	x:Key="BackgroundBrush" StartPoint="0,0" EndPoint="0,1">
        	<GradientStop Color="Black" Offset="0.7" />
        	<GradientStop Color="DimGray" Offset="0.0" />
    	</LinearGradientBrush>
	</UserControl.Resources>
   <Grid>
  	<Rectangle
     	Opacity="0.6"
     	RadiusX="2"
     	RadiusY="2"
     	StrokeThickness="1"
     	Fill="{StaticResource BackgroundBrush}"
     	Stroke="#FF2B2B2B" />
  	<ContentControl
     	FontFamily="Segoe UI"
     	FontWeight="Bold"
     	Width="Auto"
     	Height="Auto"
     	Margin="0,0,0,0"
     	FontSize="12"
     	HorizontalAlignment="Center"
     	VerticalAlignment="Center">
     	<ContentControl.Style>
        	<Style
           	TargetType="ContentControl">
           	<Style.Triggers>
              	<DataTrigger
                 	Value="True"
                 	Binding="{Binding ElementName=this, Path=DataContext.Value, ConverterParameter=0, Converter={StaticResource CompareEqualConverter}}">
                 	<Setter
                    	Property="ContentTemplate"
                    	Value="{StaticResource TplNormal}" />
              	</DataTrigger>
              	<DataTrigger
                 	Value="True"
                 	Binding="{Binding ElementName=this, Path=DataContext.Value, ConverterParameter=1, Converter={StaticResource CompareEqualConverter}}">
                 	<Setter
                    	Property="ContentTemplate"
                    	Value="{StaticResource TplWarning}" />
              	</DataTrigger>
              	<DataTrigger
                 	Value="True"
                 	Binding="{Binding ElementName=this, Path=DataContext.Value, ConverterParameter=2, Converter={StaticResource CompareEqualConverter}}">
                 	<Setter
                    	Property="ContentTemplate"
                    	Value="{StaticResource TplAlarm}" />
              	</DataTrigger>
           	</Style.Triggers>
        	</Style>
     	</ContentControl.Style>
  	</ContentControl>
   </Grid>
</UserControl>

sebastian

Administrator

Freitag, 3. Januar 2025, 08:01

Teste mal die beiden demos aus dem anhang.
Im Prinzip kann man so bei jedem Objekt die Farbe animieren.

ColorFadeAnimation.zip
ColorSwitchAnimation.zip

zunder

Newbie

Freitag, 3. Januar 2025, 15:01

Viele Dank,
Die ColorAnimationUsingKeyFrames war genau der richtige Hinweis.
mein Beispiel mit der SwitchAnimation und als zip
im Übrigen hat das mit dem Fade auch super funktioniert.
Bis ich das Objektorientierte Programmieren wirklich eigenständig kann brauche ich noch ein ganzes extra Leben :D

Grüße
Zunder

Quellcode

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<UserControl
  x:Name="this"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  xmlns:sys="clr-namespace:System;assembly=mscorlib"
  mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300">
	<UserControl.Resources>
  	<Storyboard
    	x:Key="HighlightedColorStoryboard">
      	<ColorAnimationUsingKeyFrames
        	Duration="0:0:1.6"
        	Storyboard.TargetProperty="Foreground.Color"
        	RepeatBehavior="Forever">
          	<ColorAnimationUsingKeyFrames.KeyFrames>
            	<DiscreteColorKeyFrame
              	Value="White"
              	KeyTime="0:0:0.8" />
            	<DiscreteColorKeyFrame
              	Value="Red"
              	KeyTime="0:0:0.8" />
          	</ColorAnimationUsingKeyFrames.KeyFrames>
      	</ColorAnimationUsingKeyFrames>
  	</Storyboard>
    	<DataTemplate x:Key="TplNormal">
      	<TextBlock
        	Foreground="White"
        	Text="Wasserkreis" />
    	</DataTemplate>
    	<DataTemplate x:Key="TplWarning">
      	<TextBlock
        	Foreground="Orange"
        	Text="Wasserkreis" />
    	</DataTemplate>
    	<DataTemplate x:Key="TplAlarm">
      	<TextBlock
        	Text="Wasserkreis">
          	<TextBlock.Triggers>
            	<EventTrigger
              	RoutedEvent="TextBlock.Loaded">
                	<BeginStoryboard
                  	Storyboard="{StaticResource HighlightedColorStoryboard}" />
            	</EventTrigger>
          	</TextBlock.Triggers>
      	</TextBlock>       	 
    	</DataTemplate>
    	<LinearGradientBrush
      	x:Key="BackgroundBrush" StartPoint="0,0" EndPoint="0,1">
        	<GradientStop Color="Black" Offset="0.7" />
        	<GradientStop Color="DimGray" Offset="0.0" />
    	</LinearGradientBrush>
	</UserControl.Resources>
	<Grid>
  	<Rectangle
    	Opacity="0.6"
    	RadiusX="2"
    	RadiusY="2"
    	StrokeThickness="1"
    	Fill="{StaticResource BackgroundBrush}"
    	Stroke="#FF2B2B2B" />
      	<ContentControl
        	FontFamily="Segoe UI"
        	FontWeight="Bold"
        	Width="Auto"
        	Height="Auto"
        	Margin="0,0,0,0"
        	FontSize="12"
        	HorizontalAlignment="Center"
        	VerticalAlignment="Center">
          	<ContentControl.Style>
            	<Style
              	TargetType="ContentControl">
               	<Style.Triggers>
                 	<DataTrigger
                   	Value="True"
                   	Binding="{Binding ElementName=this, Path=DataContext.Value, ConverterParameter=0, Converter={StaticResource CompareEqualConverter}}">
                   	<Setter Property="ContentTemplate" Value="{StaticResource TplNormal}" />
                 	</DataTrigger>
                 	<DataTrigger
                   	Value="True"
                   	Binding="{Binding ElementName=this, Path=DataContext.Value, ConverterParameter=1, Converter={StaticResource CompareEqualConverter}}">
                   	<Setter Property="ContentTemplate" Value="{StaticResource TplWarning}" />
                 	</DataTrigger>
                 	<DataTrigger
                   	Value="True"
                   	Binding="{Binding ElementName=this, Path=DataContext.Value, ConverterParameter=2, Converter={StaticResource CompareEqualConverter}}">
                   	<Setter Property="ContentTemplate" Value="{StaticResource TplAlarm}" />
                 	</DataTrigger>
               	</Style.Triggers>
            	</Style>
          	</ContentControl.Style>
      	</ContentControl>
	</Grid>
</UserControl>
»zunder« hat folgende Datei angehängt: