This is odd. I have a Textblock (call it ErrorMessage_Textblock) in .xaml and when I tried to access and change the text of it in .xaml.cs, it throws me an error saying "The name 'ErrorMessage_Textblock' does not exist in the current context"
Basically, the ErrorMessage_Textblock is suppose to be empty when the program runs. When the user clicks the Start Button, my code in .xaml.cs checks to see if the user filled all the necessary information in the Textboxes. If there are some missing information, it will pass on a string to the ErrorMessage_Textblock -- like "please enter where to save the files."
SideMenuControl.xaml:
<UserControl x:Class="Fasetto.Word.SideMenuControl"
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:local="clr-namespace:Fasetto.Word"
xmlns:core="clr-
namespace:Fasetto.Word.Core;assembly=Fasetto.Word.Core"
mc:Ignorable="d" d:DesignWidth="900" d:DesignHeight="1000"
Background="#FF2D2D30">
<UserControl.Template>
<ControlTemplate TargetType="UserControl">
<Border>
//some code ...
<Button
Click="StartButton"
Content="Start" FontSize="30" Padding="1,1,1,1" Foreground="Lime"
BorderBrush="Red"
/>
<TextBlock x:Name="ErrorMessage_Textblock" Foreground="OrangeRed"
FontFamily="/VIL_GUI_V5.0;component/Fonts/#Lato Light"
Margin="50,10,50,510" FontSize="20"
/>
SideMenuControl.xaml.cs: (note: line 7 throws me an error in VS)
public void StartButton(object sender, RoutedEventArgs e) {
if (Fasetto.Word.Core.IoC.Settings.Monaco_Report_Type.EditedText
== null || Fasetto.Word.Core.IoC.Settings.Monaco_Report_Type.EditedText == "")
{
//do something
ErrorMessage_Textblock = "please enter Report Type (Monaco)";
}
I found my own answer. You already have access to a Button, so you can find the grid it belongs to. Then, you can find the TextBlock. Only thing is that the TextBlock belongs to the same grid as the Button.
For the complete guide and code, click this link: