Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to measure a canvas that has auto height and width

I'm a beginner in silverlight so i hope i can get an answer that brings me some more light in the measure process of silverlight.

I found an interessting flap out control from silverlight slide control and now I try to use it in my project. So that the slide out is working proper, I have to place the user control on a canvas. The user control then uses for itself the height of its content. I just wanna change that behavior so that the height is set to the available space from the parent canvas.

You see the uxBorder where the height is set. How can I measure the actual height and set it to the border?

I tried it with Height={Binding ElementName=notificationCanvas, Path=ActualHeight} but this dependency property has no callback, so the actualHeight is never set.

What I want to achieve is a usercontrol like the tweetboard per example on Jesse Liberty's blog

Sorry for my English writing, I hope you understand my question.

<Canvas x:Name="notificationCanvas" Background="Red">
            <SlideEffectEx:SimpleSlideControl GripWidth="20" GripTitle="Task"  GripHeight="100">
                <Border x:Name="uxBorder"
                  BorderThickness="2"
                  CornerRadius="5"
                  BorderBrush="DarkGray"
                  Background="DarkGray"
                  Padding="5" Width="300"
                  Height="700"
                  >
                    <StackPanel>
                        <TextBlock Text="Tasks"></TextBlock>
                        <Button x:Name="btn1" Margin="5" Content="{Binding ElementName=MainBorder, Path=Height}"></Button>
                        <Button x:Name="btn2" Margin="5" Content="Second Button"></Button>
                        <Button x:Name="btn3" Margin="5" Content="Third Button"></Button>
                        <Button x:Name="btn1_Copy" Margin="5" Content="First Button"/>
                        <Button x:Name="btn1_Copy1" Margin="5" Content="First Button"/>
                        <Button x:Name="btn1_Copy2" Margin="5" Content="First Button"/>
                        <Button x:Name="btn1_Copy3" Margin="5" Content="First Button"/>
                        <Button x:Name="btn1_Copy4" Margin="5" Content="First Button"/>
                        <Button x:Name="btn1_Copy5" Margin="5" Content="First Button"/>
                        <Button x:Name="btn1_Copy6" Margin="5" Content="First Button"/>
                    </StackPanel>
                </Border>
            </SlideEffectEx:SimpleSlideControl>

like image 763
Wymmeroo Avatar asked Mar 18 '10 12:03

Wymmeroo


People also ask

How do you measure the height and width of a canvas?

You can get the width and height of a canvas element simply by accessing those properties of the element. For example: var canvas = document. getElementById('mycanvas'); var width = canvas.

What is the default height and width of canvas area?

By default, the browser creates canvas elements with a width of 300 pixels and a height of 150 pixels. You can change the size of a canvas element by specifying the width and height attributes.

How do you find the full width of a canvas?

Code to make canvas occupy full page :width = window. innerWidth; canvas.


1 Answers

Hey - a couple of things:

  • I'm guessing it's just a typo, but: "{Binding ElementName=MainBorder, Path=Height}" should be "{Binding ElementName=uxBorder, Path=Height}" (or ActualHeight)
  • The SlideEffect appears to set a clip geometry, which is going to affect how "big" it looks

    RectangleGeometry clipRect = new RectangleGeometry();

    clipRect.Rect = new Rect(0, 0, panel.ActualWidth, host.Height);

    host.Clip = clipRect;

If you comment out the above lines from the slide control, you should see a noticeable change in how big the panel looks.

like image 85
JerKimball Avatar answered Nov 13 '22 14:11

JerKimball