c# - Set the width of scrollbars programmatically -
i have application, uses wpf on windows toolkit framework. set width of scrollbars scrollviewers programmatically. found many examples set width via xaml. how can define width of scrollbars programmatically?
unfortunately not find property or method on scrollviewer set width of scrollbars.
var viewer = new scrollviewer(); viewer.magicproperty = 42; // not exist
also properties on systemparameters unfortunately read-only.
verticalscrollbarwidth.verticalscrollbarwidth = 42; // read-only
edit: wpf 1 of multiple toolkit frameworks in application. use custom gui abstraction layer supporting windows (wpf), linux (gtk#) , macos x (in future). user interface encapsulated in os independent way. therefore makes no sense use xaml.
easiest way set x:name
property, can access scrollviewer
in code.
or use binding: http://www.tutorialspoint.com/wpf/wpf_data_binding.htm
binding
useful if want manipulate multile scrollviewers
, set same values.
edit: can create scrollviewer in code , set parameters. need way insert visualtree among other controls. need instance of container , use children.add()
method
however i'd recommend use xaml can , leave code application logic, not ui building.
edit 2: can try:
style mystyle = new style(typeof(scrollbar)); mystyle.setters.add(new setter(widthproperty, 40)); scrollviewer.style = mystyle;
edit 3: found solution. can add resourcedictionary.xaml
, add style it:
<style x:key="{x:type scrollbar}" targettype="{x:type scrollbar}"> <setter property="minwidth" value="35" /> <setter property="width" value="35" /> </style>
then load @ runtime so:
resources.mergeddictionaries.add(application.loadcomponent(new uri(@"dictionary.xaml", urikind.relative)) resourcedictionary);
Comments
Post a Comment