vb.net - WPF: How to create the visual tree for dynamically generated DataGrid objects? -


if create datagrid in code behind arbitrary columns added can not visual tree created datagrid. need edit cellstyle properties of particular rows dynamically, able use visualtreehelper function on datagrid objects @ run time. how can build visual tree datagrid objects created dynamically? tree built no problems if use xaml build 1 @ design-time, not sure how dynamic case.

a trivial sample case problem such:

    <window x:class="mainwindow"     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"     title="mainwindow" height="350" width="525">         <grid name="maingrid" />     </window> 

with code behind as:

    class mainwindow         dim dg datagrid         dim col datagridtextcolumn          sub new()             initializecomponent()              col.header = "head0rr"             dg.columns.add(col)             maingrid.children.add(dg)         end sub     end class 

but wpf tree visualizer shows datagrid created having no parents or children, , visualtreehelper function not work.

the tree built no problems if use xaml build 1 @ design-time, not sure how dynamic case.

first of all, "xaml" , "dynamic" not mutually exclusive. absolutely sure need build grid , access cellstyles through procedural (vb) code? there multiple options xaml easier, more maintainable, , more dynamic explicitly scanning visual tree. example:

as why can't see items in visual tree: when trying access it? won't populate instantly. may need wait loaded event, or statuschanged event of datagrid's itemcontainergenerator.


Comments