开发者

Silverlight 4 Canvas Height and Width Binding

开发者 https://www.devze.com 2023-03-10 04:26 出处:网络
I am working on silverlight apps and I want to bind the Canvas Width and Height through XAML but how I can bind it.Because the canvas width and height I had tried to bind it but will not working in my

I am working on silverlight apps and I want to bind the Canvas Width and Height through XAML but how I can bind it.Because the canvas width and height I had tried to bind it but will not working in my case so if you guys have any other binding way to bind it so please put some somple code so I can figure out the solution of this problem.

I wan to bind this with the Image Height and Width s开发者_如何转开发o the some times Image size is 1000 x 1200 and some times image size will be 1400 x 1700 so how I can bind it?

<Viewbox 
            Grid.Row="1" 
            Grid.Column="0"
            Grid.ColumnSpan="2">
                <Canvas
                Height="1000"
                HorizontalAlignment="Center"
                VerticalAlignment="Center"
                Width="1200">

                    <Image x:Name="imgEdit" 
                                Cursor="Hand"
                                MouseLeftButtonDown="imgEdit_MouseLeftButtonDown"
                                MouseMove="imgEdit_MouseMove"
                                MouseLeftButtonUp="imgEdit_MouseLeftButtonUp"   
                                HorizontalAlignment="Center"
                               VerticalAlignment="Center" 
                               RenderTransformOrigin="0.5, 0.5">

                    <Image.Effect>
                        <l:briconEffect 
                                    Brightness="{Binding ElementName=bVal, Path=Value}"
                                    Contrast="{Binding ElementName=cVal, Path=Value}"
                                    Gamma="{Binding ElementName=gVal,Path=Value}"
                                    RedRatio="{Binding ElementName=rVal,Path=Value}"
                                    BlueRatio="{Binding ElementName=blueVal,Path=Value}"
                                    GreenRatio="{Binding ElementName=greenVal,Path=Value}"/>
                    </Image.Effect>

                    <Image.RenderTransform>

                        <TransformGroup>
                            <RotateTransform x:Name="Rotator">
                                <RotateTransform.Angle>
                                    <Binding ElementName="sldVerHorizontal" Path="Value" Mode="TwoWay"/>
                                </RotateTransform.Angle>
                            </RotateTransform>

                            <ScaleTransform x:Name="Scale">
                                <ScaleTransform.ScaleX>
                                    <Binding ElementName="sldZoomInOut" Path="Value" Mode="TwoWay"/>
                                </ScaleTransform.ScaleX>
                                <ScaleTransform.ScaleY>
                                    <Binding ElementName="sldZoomInOut" Path="Value" Mode="TwoWay"/>
                                </ScaleTransform.ScaleY>
                            </ScaleTransform>
                        </TransformGroup>

                    </Image.RenderTransform>


                </Image>

                <Border
                        x:Name="maskBorder"
                        MinWidth="200"
                        MinHeight="200"
                        BorderBrush="Black"
                        BorderThickness="5"
                        Canvas.Left="250" 
                        Cursor="Hand"
                        Canvas.Top="250">

                    <Rectangle
                        MinWidth="200"
                        MinHeight="200"
                        x:Name="maskRect"
                        Canvas.Left="250" 
                        Cursor="Hand"
                        Canvas.Top="250">
                    </Rectangle>
                </Border>
            </Canvas>
        </Viewbox>


You may bind the Canvas Width and Height properties using Element Binding like this

Width={Binding Element=imgEdit,Path=ActualWidth} Height={Binding Element=imgEdit,Path=ActualHeight}

You may also wrap the Canvas within a ScrollViewer of fixed Width and Height to limit for user screen size.

0

精彩评论

暂无评论...
验证码 换一张
取 消