Hello community,
I am a beginner in c# and wpf. I used to program Python, so I am not totally new in programming. I currently try to program a License generator for my company. Since I really want to learn wpf with generating my own GUI, I spend a lot of time with the resource dictionary.
Right now, I stuck with the Text Box.
I created a Text Box dictionary, and everything locks fine. I can type on it, but if I try to read the written text it is always empty.
Now I hope someone of you guys can help me to understand what my fault is. Thanks!
Best,
Mathias
Text Box dictionary:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Style TargetType="{x:Type TextBox}" x:Key="ModernTextBox"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type TextBox}"> <Border CornerRadius="10" Background="#353340" Width="{TemplateBinding Width}" Height="25"> <Grid> <Rectangle StrokeThickness="1"/> <TextBox Margin="5,-3,0,0" CaretBrush="White" BorderThickness="0" Background="Transparent" VerticalContentAlignment="Center" Padding="5" Foreground="#cfcfcf" x:Name="text_box"/> <TextBlock IsHitTestVisible="False" Text="{TemplateBinding Uid}" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="10,0,0,0" FontSize="10" Foreground="DarkGray" Grid.Column ="1"> <TextBlock.Style> <Style TargetType="{x:Type TextBlock}"> <Style.Triggers> <DataTrigger Binding="{Binding Text, ElementName=text_box}" Value=""> <Setter Property="Visibility" Value="Visible"/> </DataTrigger> </Style.Triggers> <Setter Property="Visibility" Value="Hidden"/> </Style> </TextBlock.Style> </TextBlock> </Grid> </Border> </ControlTemplate> </Setter.Value> </Setter> </Style> </ResourceDictionary>
Text Box Call:
<TextBox Name="mac_textbox" Uid="Mac" Width="300" Style="{StaticResource ModernTextBox}"/>
void SubmitButton_Click(object sender, RoutedEventArgs e) { Console.WriteLine(mac_textbox.Text); }