Changing Color of Textblock Dynamically and a few other Q's.
Posted: 09 Dec 2020, 09:58
I'm trying to change the color of a textblock during runtime, depending on team colors in our game.
The TextBlock is defined in .Xaml via a UserControl which is invoked when a player dies/scores.
.Xaml Code:
.Xaml Code where UserControl is put:
c++ Code trying to switch color:
The problem that happens is that after the first color is set I can't change the color. so if this Usercontrol is invoked once with a red color, all other times I try to invoke this Prompt message it keeps the first color set. I tried to get the Textblock Brush and the brush foreGround color has changed but without any visual update. Another weird thing regarding this code is that if I try to use instead of the application crashes. Using when creating a new brush has never been an issue before until now and I can't understand why this should be a problem in this specific Case.
Bonus Questions:
Also we are using a NoesisGUI integrated in our Vulkan application and for some reason the application (SOMETIMES) crashes when is called on the previous View and a new view is set and we can't figure out why this is.
And (SOMETIMES) when we try to set the rendertarget via SetRenderTarget the application crashes, again we have no idea what the issue might be as we are fairly certain our integration is correct.
Worth noting is that these "Bonus Questions"-crashes occur very rarely. If you guys have any idea what might cause these problems any tip would be much appreciated.
//The Toad
The TextBlock is defined in .Xaml via a UserControl which is invoked when a player dies/scores.
.Xaml Code:
Code: Select all
<UserControl x:Class="CrazyCanvas.PromptGUI"
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:noesis="clr-namespace:NoesisGUIExtensions;assembly=Noesis.GUI.Extensions"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:CrazyCanvasNoesisGUI"
mc:Ignorable="d"
TextElement.FontFamily="gogono_cocoa_mochi.ttf#Gogono Cocoa Mochi"
d:DesignHeight="100" d:DesignWidth="100"
x:Name="PROMPT_UC">
<UserControl.Resources>
<!-- A few StoryBoards here -->
<Style TargetType="{x:Type TextBlock}"
x:Key="PromptTextStyle">
<Setter Property="FontSize" Value="26" />
<Setter Property="ForeGround" Value="White" />
<Setter Property="noesis:Text.Stroke" Value="Black" />
<Setter Property="noesis:Text.StrokeThickness" Value="2.5" />
</Style>
</UserControl.Resources>
<Grid x:Name="PROMPT_GRID">
<TextBlock x:Name="PROMPT_TEXT" Text="" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="26" Visibility="Hidden" noesis:Text.Stroke="Black" noesis:Text.StrokeThickness="2.5" RenderTransformOrigin="0.5 0.5" >
<TextBlock.RenderTransform>
<TransformGroup x:Name="transformGroup">
<ScaleTransform/>
</TransformGroup>
</TextBlock.RenderTransform>
<TextBlock.Foreground>
<SolidColorBrush Color="Red"/>
</TextBlock.Foreground>
</TextBlock>
<TextBlock x:Name="SMALL_PROMPT_TEXT" Text="" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="26" Foreground="Red" Visibility="Hidden" noesis:Text.Stroke="Black" noesis:Text.StrokeThickness="2.5" RenderTransformOrigin="0.5 0.5">
<TextBlock.RenderTransform>
<TransformGroup x:Name="smallTransformGroup">
<ScaleTransform/>
</TransformGroup>
</TextBlock.RenderTransform>
</TextBlock>
</Grid>
</UserControl>
Code: Select all
<Viewbox Grid.Row="4" Grid.Column="4" Grid.ColumnSpan="2" HorizontalAlignment="Center" VerticalAlignment="Center">
<uc:PromptGUI x:Name="PROMPT" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Viewbox>
Code: Select all
void PromptGUI::DisplayPrompt(const LambdaEngine::String& promptMessage, uint8 teamIndex)
{
Noesis::SolidColorBrush* pBrush = new Noesis::SolidColorBrush();
UNREFERENCED_VARIABLE(teamIndex);
if (teamIndex != UINT8_MAX)
{
Noesis::Style* pStyle = FrameworkElement::FindResource<Noesis::Style>("PromptTextStyle");
m_pPromptTextblock->SetStyle(pStyle);
}
else
{
pBrush->SetColor(Noesis::Color::Red());
m_pPromptTextblock->SetForeground(pBrush);
}
m_pPromptTextblock->SetText(promptMessage.c_str());
m_pPromptVisibilityStoryboard->Begin();
m_pPromptStoryboard->Begin();
}
Code: Select all
Noesis::Ptr<Noesis::SolidColorBrush> pBrush = *new Noesis::SolidColorBrush()
Code: Select all
Noesis::SolidColorBrush* pBrush = new Noesis::SolidColorBrush();
Code: Select all
Noesis::Ptr<Noesis::SolidColorBrush> pBrush = *new Noesis::SolidColorBrush()
Bonus Questions:
Also we are using a NoesisGUI integrated in our Vulkan application and for some reason the application (SOMETIMES) crashes when
Code: Select all
Noesis::Ptr<Noesis::IView>::Reset()
And (SOMETIMES) when we try to set the rendertarget via SetRenderTarget the application crashes, again we have no idea what the issue might be as we are fairly certain our integration is correct.
Worth noting is that these "Bonus Questions"-crashes occur very rarely. If you guys have any idea what might cause these problems any tip would be much appreciated.
//The Toad