question

EmonHaque-1485 avatar image
0 Votes"
EmonHaque-1485 asked EmonHaque-1485 edited

Why doesn't TextBox's ScrollBar get the Default Style?

First of all, this way it solved the problem BUT made me think why would I need another ControlTemplate, EditTextScrollbar, when I've set the ScrollBar's DefaultStyle globally in App.cs, all that I need is set the Margin of the ScrollBar inside TextBox. So I've tried, without the, EditTextScrollbar, ControlTemplate, this way:

 inputBox.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
 inputBox.Resources.Add(typeof(ScrollBar), new Style() {
     Setters = { 
         //new Setter(ScrollBar.TemplateProperty, new VScrollTemplate()),
         new Setter(MarginProperty, new Thickness(0,20,-26,0)) 
     }
 })

and it looks like this:

94892-test.gif

So it doesn't get the DefaultStyle. I've to uncomment new Setter(ScrollBar.TemplateProperty, new VScrollTemplate()) to make it pickup the style, why? Is there anything left to apply the DefaultStyle of ScrollBar?

windows-wpf
test.gif (105.0 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

EmonHaque-1485 avatar image
0 Votes"
EmonHaque-1485 answered EmonHaque-1485 edited

Sometimes the solution comes to my mind immediately after I post! Here's how it works, without another ControlTemplate:

 inputBox.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
 inputBox.Resources.Add(typeof(ScrollBar), new Style() {
     //BasedOn = (Style)FindResource(typeof(ScrollBar)),
     BasedOn = App.scrollBarStyle,
     TargetType = typeof(ScrollBar),
     Setters = { new Setter(MarginProperty, new Thickness(0,20,-26,0)) }
 });

It's another problem, every multiline textbox in my App will have its own resource. With a global instance of Style, multilineTextScrollStyle ,

 multilineTextScrollStyle = new Style(typeof(ScrollBar), scrollBarStyle) {
     Setters = { new Setter(ScrollBar.MarginProperty, new Thickness(0, 20, -26, 0)) }
 };

it can be reduced to: inputBox.Resources.Add(typeof(ScrollBar), App.multilineTextScrollStyle);, again, every multiline textbox will have the same Resource. All that I need, actually, is Left and Top Margin on the ScrollBar inside TextBox. Is it possible to set that directly instead of making Style/Resource?

If I do inputBox.SetValue(ScrollBar.MarginProperty, new Thickness(0, 20, -26, 0)); it applies margin to the TextBox.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.