locked
XAML Styles Not Overriding Defaults RRS feed

  • Question

  • Hello, everyone! I'm trying to override the defaults and set the MinHeight and Height of the Vertical ScrollBar inside my textboxes. I need to do this because my textboxes are small (not too small, though), and as a result the default scrollbars are too large to fit inside the textbox. Here's my XAML code to override the default ScrollBar defaults:

    <Page.Resources>
            <Style TargetType="ScrollBar">
                <Setter Property="Height" Value="40" />
                <Setter Property="MinHeight" Value="1" />
            </Style>
        </Page.Resources>

    I've searched online for help regarding this issue, but after hours of searching I still couldn't find anything that helped with this specific issue. I've also copied the default ScrollViewer template from here and modified it, but I didn't have any luck.

    I have my VerticalScrollBarVisibility set to True, so I can see the Vertical ScrollBar when I hover my mouse over a TextBox. The strange part is that my XAML styling works. However, if I enter enough text into the TextBox that would normally make the ScrollBar appear when it is set to Auto, the ScrollBar will change and turn back into the default, which is too big.

    I'm pretty lost here, so could someone help me out, please?

    Additionally, I've noticed that you still cannot change the color of the caret in a textbox. If this is true, is there some sort of workaround for it? My textboxes are black, and the caret cannot stay black in this situation.

    Thank you very much!

    Saturday, March 3, 2012 2:53 AM

Answers

  • Hi Hydrakiller4000,

    The ScrollBars have a minimum MinHeight. They do not draw well and cannot be targeted easily if they are smaller than that. It sounds like your TextBoxes really are too small to handle multiple lines. I would make them larger, either all of the time or have them grow when the user sets focus to them.

    There is no way to control the caret color. Since you only need the caret when the user is editing the TextBox you can leave its Background as Black normally but use a template which changes the Background to a lighter color when the user is editing it.

    --Rob

    Saturday, March 3, 2012 3:23 AM
    Moderator