Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>The tree is built with no problems if I use XAML to build one at design-time, but I am not sure how to do this for a dynamic case.</p> </blockquote> <p>First of all, "XAML" and "dynamic" are not mutually exclusive. Are you absolutely sure you need build the grid and access CellStyles through procedural (VB) code? There are multiple options from XAML that are easier, more maintainable, and more dynamic than explicitly scanning the visual tree. For example:</p> <ul> <li><p>Declare <a href="http://msdn.microsoft.com/en-us/library/system.windows.datatemplate.aspx" rel="nofollow">DataTemplates</a> per column with <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.datagridtemplatecolumn.aspx" rel="nofollow">DataGridTemplateColumn</a></p></li> <li><p>Use <a href="http://msdn.microsoft.com/en-us/library/system.windows.datatrigger.aspx" rel="nofollow">DataTrigger</a>s in a <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.datagrid.cellstyle.aspx" rel="nofollow">DataGrid.CellStyle</a>, <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.datagridcolumn.cellstyle.aspx" rel="nofollow">DataGridColumn.CellStyle</a>, or <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.datagrid.rowstyle.aspx" rel="nofollow">DataGrid.RowStyle</a></p></li> <li><p>Define alternating / cycling row styles as described at <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.itemscontrol.alternationcount.aspx" rel="nofollow">AlternationCount</a></p></li> </ul> <p>As for why you can't see items in the visual tree: When are you trying to access it? It won't populate instantly. You may need to wait for the <code>Loaded</code> event, or the <code>StatusChanged</code> event of the DataGrid's <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.itemscontrol.itemcontainergenerator.aspx" rel="nofollow">ItemContainerGenerator</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COA form I am designing needs to create a new datagrid in response to user input; I am doing this in a tabcontrol which adds a new tabitem containing the newly generated datagrid. This behavior is necessary for the application I am developing, and I was unsure of a method to do this in XAML. I am trying to access the datagrid's child elements after it's creation in the application logic in order to change the cellstyle properties of particular rows generated in the new datagrid object.
      singulars
    2. COI assume the "particular rows" are identified by the kind of data that they display, so you should be able to define the style differences using DataTriggers. If you need to generate columns dynamically, you could still define the actual styles with DataTriggers in XAML and do something like `col.CellStyle = FindResource("SpecialCellStyle")` where "SpecialCellStyle" is the `x:Key` of your XAML resource.
      singulars
    3. COCould you point me to a resource to help me figure out how to use XAML to allow new datagrid objects to be created and formatted the way I need so I don't have to do it in code behind? I am also experiencing a similar problem with content I create and add to a tabitem that gets added to a tablist I use as an itemsource for a tabcontrol; anything I create within and including the tabitem does not get a visual tree generated for it for me to use to manipulate child or parent objects with.
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload