Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

WPF Textbox visible in Designer but not application

I’m brand new WPF so I may be missing something obvious. I’ve got a TextBox in the designer, that looks fine and is visible, however, when running the app it isn’t visible while the other elements are still visible.

Designer:

Designer view

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Application:

Application view

Xaml:

<Window x:Class="Windows.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:Windows"
        mc:Ignorable="d"
        Title="UniPaste for Windows" Height="450" Width="800"
        Background="#333">
    <Grid>
        <TextBlock TextWrapping="Wrap" Text="UniPaste for Windows" Margin="0,0,0,348" TextAlignment="Center" VerticalAlignment="Center" Foreground="White" FontSize="32" FontFamily="Consolas Bold"/>
        <TextBlock TextWrapping="Wrap" Text="Email" Margin="0,90,0,0" TextAlignment="Center" VerticalAlignment="Top" Foreground="White" FontSize="24" FontFamily="Consolas"/>
        <TextBox Name="Email" Margin="340,123,340,290" Background="White" Height="23" TextChanged="EmailChanged"/>
    </Grid>
</Window>

>Solution :

Take advantage of the Grid component and its row and column definitions to align the elements you want.
What was happening is that at runtime the textbox had no line to attach to

<Window x:Class="WpfApp1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:local="clr-namespace:WpfApp1"
    mc:Ignorable="d"
    Title="MainWindow" Height="450" Width="800"
    Background="#333">
<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>
    <TextBlock Grid.Row="0" 
               Margin="0 25 0 0"
               TextWrapping="Wrap" 
               Text="UniPaste for Windows" 
               TextAlignment="Center" 
               VerticalAlignment="Center" 
               Foreground="White" 
               FontSize="32" 
               FontFamily="Consolas Bold"
               />
    <TextBlock Grid.Row="1" 
               Margin="0 25 0 0"
               TextWrapping="Wrap" 
               Text="Email" 
               TextAlignment="Center" 
               VerticalAlignment="Top" 
               Foreground="White" 
               FontSize="24" 
               FontFamily="Consolas"/>
    <TextBox Grid.Row="2"   
             Name="Email" 
             Margin="0 25 0 0"
             HorizontalAlignment="Center" 
             Background="White" 
             Height="23" Width="100" 
             TextChanged="EmailChanged" 
             />

</Grid>

Runtime Window

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading