Friday 15 April 2011

wpf - C# Custom Canvas class, ActualHeight/Width are always 0 -


I want to apply the square which attracts the grid on canvas , but the problem It is set to real-life and actual height 0.

Enter image description here canvas is all gray area.

Can someone tell me what I am doing, I'm a newbie in C #. Thanks!

  Class ImageGrid: Canvas {Private Double GridSystem = 50; Public imagegrid () {background = new solid collar brush (color. Darkgrey); } Public Zero Drawgrid () {Child. clean (); #region Draw Image // Todo - Image # Underline # Draw For Drag Grid (double x = 0; x & gt; realview; x + = grid size) {line line = new line (); Line. X1 = x; Line. X2 = x; Line. Y1 = 0; Line. Y2 = realism; // Why 0? Line. Stroke = brush Black; Line.Trokhthika = 1; Children.Add (line); } (Double y = 0; y & gt; realh; y + = grid size) {line line = new line (); Line. X1 = 0; Line. X2 = realhigh; // Why 0? Line. Y1 = y; Line. Y2 = y; Line. Stroke = brush Black; Line.Trokhthika = 1; Children.Add (line); } #grand}}  

Imagegrid Call:

  Public partial square main window: window {public key window ()} {InitializeComponent (); ImageGrid ig = new ImageGrid (); Grid.Children.Add (IG); Ig.DrawGrid (); }}  

You must wait for the layout pass before you get the actual height / width Try calling ig.DrawGrid in loaded handlers.

  public partial square main window: window {public MainWindow () {InitializeComponent (); ImageGrid ig = new ImageGrid (); Grid.Children.Add (IG); Ig.Loaded + = ImageGrid_Loaded; } Zero imagegrid_loaded (object sender, routing and augmented EG) {ig.DrawGrid (); Note from  

This property has a calculated value based on other height inputs, and the layout system value is based on the actual rendering pass layout Is determined by the system, and therefore the set of properties can be a little behind behind the value, such as the height that is the basis of the input change.

Because the actual hit is a calculated value, you should know that the layout system may result in changes in more than one or incremental report as a result of various actions. The layout system can calculate the required measurement space for basic elements, obstacles by the original element, and so on.


No comments:

Post a Comment