I'm making a small application using .NET Core 6 WPF. I'm trying to get user input from a TextBox, but it returns a value I set through XAML. This is how I declare a TextBox:
<TextBox Name="TaskTextBox" Margin="0, 0, 0, 20" Text="Task" Style="{StaticResource InputFieldStyle}"/>
<Button
Name="SaveButton"
Click="SaveButton_OnClick"
Style="{StaticResource HomeTaskEditButtonStyle}"
Background="#5abf26"
HorizontalAlignment="Left"
Width="100">
<TextBlock
Text="Save"
Foreground="White"
FontSize="20"/>
</Button>
And here is how I try to get the input:
private void SaveButton_OnClick(object sender, RoutedEventArgs e)
{
var taskText = TaskTextBox.Text; // Returns "Task", But I entered "Test"
var lessonText = LessonTextBox.Text;
// Next Logic
}
And here is my TextBox Style:
<Style x:Key="InputFieldStyle" TargetType="TextBox">
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="TextBox">
<Border
CornerRadius="10"
Background="#464646"
Padding="5">
<TextBox
Text="{TemplateBinding Text}"
FontSize="16"
Margin="1"
BorderThickness="0"
Background="Transparent"
Padding="5"
Foreground="White"
TextWrapping="WrapWithOverflow"
CaretBrush="White"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
I request TaskTextBox.Text
when the button is pressed.
I don't know how to fix this.