In EntityRelationships sample I use the following code ( in blue) to expand and collapse nodes.
This works great until I change the size of the node. At that point the collapse does not collapse the DataGrid but it does make the DataGrid not visible. Is there anything I can do to make the DataGrid collapse after a size change.
Thanks
Rich
public static void SetTableVisibility(Button expanderButton, Node tableNode)
{
// find the Node’s DataGrid
DataGrid grid = tableNode.FindNamedDescendant(“dataGrid”) as DataGrid;
if (grid == null)
return;
Uri uri;
ImageSource imgSource;
Image myImage;
if (grid.Visibility == Visibility.Collapsed)
{
grid.Visibility = Visibility.Visible;
uri = new Uri("images/arrow_up.png", UriKind.Relative);
}
else
{
grid.Visibility = Visibility.Collapsed;
uri = new Uri("images/arrow_down.png", UriKind.Relative);
}
imgSource = new BitmapImage(uri);
myImage = (Image)expanderButton.FindName("Expander");
myImage.Source = imgSource;
}</font>
The ResizingTool sets the Width and Height of the resized element – i.e. the element named by Part.SelectionElementName, which defaults to the whole Part.VisualElement.
If you clear the values of those two properties, I bet the panel will be arranged at its natural size, which will not include the Collapsed DataGrid.
Your question. By the way, which element has the x:Name=“NodeBackground”? Is that the element that you want users to resize?
NodeBackground was a mistake and I removed the reference in the xaml code. With your three lines of code collapse is working for a node that has been resized.