c# - Is there a code-behind equivalent for TextBlock ScrollViewer.CanContentScroll="True" for DataGridTemplateColumn? -
for textblock in xaml, can following inside datatemplate:
<textblock text="mytextblock text" verticalalignment="center" margin="0,0,5,0" scrollviewer.cancontentscroll="true" scrollviewer.horizontalscrollbarvisibility="visible"/>
but when try set scrollviewer.horizonalscrollbarvisibility, doesn't seem anything.
datatemplate textblocktemplate = new datatemplate(); frameworkelementfactory textblockelement = new frameworkelementfactory(typeof(textblock)); binding c1binding = new binding("mybindingvalue") { mode = bindingmode.twoway, updatesourcetrigger = updatesourcetrigger.propertychanged }; textblockelement.setbinding(textblock.textproperty, c1binding); textblockelement.setvalue(textblock.textwrappingproperty, textwrapping.wrap); textblockelement.setvalue(textblock.heightproperty, system.convert.todouble(23)); textblockelement.setvalue(scrollviewer.cancontentscrollproperty, true); textblockelement.setvalue(scrollviewer.horizontalscrollbarvisibilityproperty, scrollbarvisibility.visible); textblocktemplate.visualtree = textblockelement; templatecolumn.celltemplate = textblocktemplate; mydatagrid.columns.add(templatecolumn);
i trying make datagrid column has textblock shows 1 line of text, allows scroll up/down see rest of textblock.
textblock
doesn't have scrollviewer
contained in set scrolling behavior on. need wrap in scrollviewer
on can set whatever want. contrast listbox
, contain scrollviewer
in controltemplate
can take advantage of attached properties.
Comments
Post a Comment