0

This is the question I had posted. Now, I am not able to reflect the changes made to the rectangle element in the DataTemplate. I want to scaleX the rectangle depending on some values and conditions in the code-behind. I did the following :

     foreach (var rectangle in FindVisualChildren<Rectangle>(this))
     {
       if (rectangle.Name == "rectangleBarChart" && isRectangle == false)
       {
             rectangle.Fill = Brushes.MediumVioletRed;
             rectangle.Height = 10;
             rectangle.LayoutTransform = new ScaleTransform(2, 1);
             isRectangle = true;
       }
     }

But, the changes are not reflected, it uses the same old DataTemplate. Any hints to refelct the changes to the UI ?

4

1 回答 1

0
rectangle.Fill = Brushes.MediumVioletRed;
            rectangle.Height = 10;
            rectangle.LayoutTransform = new ScaleTransform(2, 1);
            isRectangle = true;
            **rectangle.UpdateLayout();**

使用 UpdateLayOut 方法进行更新。我希望这会有所帮助。

于 2012-08-07T09:50:24.930 回答