0

Can anyone figure out what is wrong with my style? The problem started when I wanted to add rounded corners to my textboxes; it looks perfectly alright but when I test the app, the textboxes do not respond; I cannot write into them, not even by adding the Text attribute.

I couldn't figure it out until I started the UI from scratch; as soon as I apply the style to the textbox, it becomes messed up, but I cannot see anything wrong with it.

<Grid>
    <TextBox x:Name="textBox" Style="{StaticResource Input}"
             HorizontalAlignment="Left"
             Margin="37,10,0,93"
             TextWrapping=" NoWrap" />
</Grid>

<Style TargetType="TextBox" x:Key="Input">
    <Setter Property="Background" Value="#FF363636"/>
    <Setter Property="Foreground" Value="#FFA8A8A8"/>
    <Setter Property="Height" Value="23"/>
    <Setter Property="Width" Value="120"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="TextBox">
                <Border BorderThickness="1"
                        BorderBrush="#FF555555"
                        Background="{TemplateBinding Background}"
                        CornerRadius="2">
                    <ContentPresenter HorizontalAlignment="Left"
                                      VerticalAlignment="Center"/>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

As an added bonus, when I test it, part of the textbox disappears.

Preview of the app, left is designer more, right is the test build

Can somebody see something I don't?

Cory
  • 61
  • 1
  • 6
  • 1
    Your style looks incomplete. Have you tried [extracting the default style](http://stackoverflow.com/questions/8825030/how-to-extract-default-control-template-in-visual-studio) into your code and modifying that? – ChrisF Feb 27 '16 at 22:38
  • @ChrisF No, I didn't know it was necessary... and also because when I've that in the past, It was miles long and could not tell what even half of it meant. – Cory Feb 27 '16 at 22:48
  • 1
    @Cory Yes, I won't lie, it's a confusing pain to do, but getting comfortable with sifting through copies of templates to get the bits you need is necessary when you want something more complex than a button, say. Unfortunately a simple ContentPresenter inside a border won't do, as there is more at play inside the template of a TextBox than that. Plus names given to components inside templates should never be changed, as you'll find a lot of the time unseen code dealing with the control itself is looking for those names in order to make it functional. – Logan Feb 29 '16 at 12:17
  • @Logan Yeah, seems that way but thanks for the input. One middle ground to doing my own templates and styles exactly the way I want, is to use 3rd-party UI kits, like mahapps.metro, which I'm experimenting with right now. Seems pretty neat but there seems to be plenty of others. Any experiences with these? – Cory Feb 29 '16 at 18:52
  • @Cory At the moment we're using DevExpress' UI kit for WPF which has its advantages. I've gotten so used to ripping templates apart to get what i want / add what i need that slowly over time it's getting to the point i can replicate what they do in their kits myself in custom controls and user controls, but better and more efficient as it's tailored to what my team needs. I would say if you can find a UI kit that does exactly what you need (even if it's just one or two controls) then go for it. Then if in 6months time you feel like you can make your own version better, do that. – Logan Mar 01 '16 at 12:18
  • @Logan Okey, thanks for the tip. I'll try out a few of these, or at least the ones I have access to (since many of them are meant for enterprises and have a high price tag), for now at least, since I'm only really starting out. – Cory Mar 01 '16 at 16:19

0 Answers0