Textbox resource dictionary

Jun 11 2021 12:28 AM

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!



Text Box dictionary:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    <Style TargetType="{x:Type TextBox}"
        <Setter Property="Template">
                <ControlTemplate TargetType="{x:Type TextBox}">
                    <Border CornerRadius="10"
                            Width="{TemplateBinding Width}" Height="25">
                            <Rectangle StrokeThickness="1"/>
                            <TextBox Margin="5,-3,0,0"
                            <TextBlock IsHitTestVisible="False"
                                       Text="{TemplateBinding Uid}"
                                       Grid.Column ="1">
                                    <Style TargetType="{x:Type TextBlock}">
                                            <DataTrigger Binding="{Binding Text, ElementName=text_box}" Value="">
                                                <Setter Property="Visibility" Value="Visible"/>
                                        <Setter Property="Visibility" Value="Hidden"/>

Text Box Call:

<TextBox Name="mac_textbox"
         Style="{StaticResource ModernTextBox}"/>
void SubmitButton_Click(object sender, RoutedEventArgs e)


Answers (4)