How to bind this

Page 1 of 1

4 Replies - 1509 Views - Last Post: 13 November 2011 - 07:30 AM Rate Topic: -----

#1 falcon eyes  Icon User is offline

  • D.I.C Head

Reputation: -4
  • View blog
  • Posts: 53
  • Joined: 16-April 07

How to bind this

Posted 03 November 2011 - 07:27 AM

Hi Every body

I have initialized C# WPF application,and in the main window class i have created a property called "Myangel", and i have Path object with the Name "indicaitor" which i created via the XML file ,i've made rotate transform for this path.

My question is how to bind "Myangel" property in the mainwindow to the "Angel" property of the Rotate Transform in the XML file?

My Code as below
<Window x:Class="CtrlTst.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525" MouseDoubleClick="Window_MouseDoubleClick">
    <Grid>
        <Path Stroke="Black" Fill="Azure" StrokeThickness="4">
            <Path.Data>
                <PathGeometry>
                    <PathFigure StartPoint="175,150" IsClosed="True">
                        <ArcSegment Point="325,150" Size="1,1" SweepDirection="Clockwise"></ArcSegment>
                    </PathFigure>
                </PathGeometry>
            </Path.Data>
        </Path>
        <Path Stroke="red" StrokeThickness="4">
            <Path.Data>
                <EllipseGeometry Center="250,150" RadiusX="100" RadiusY="100" ></EllipseGeometry>
            </Path.Data>
        </Path>
        <Path Stroke="Red"  StrokeThickness="2" Fill="Red" Name="indicaitor">
            <Path.Data>
                <PathGeometry>
                    <PathFigure StartPoint="250,150" IsClosed="False" >
                    
                        <PolyLineSegment Points="195,150,200,145,200,155,195,150"></PolyLineSegment>
                    </PathFigure>
                </PathGeometry>
                    <!--  <LineGeometry StartPoint="250,150" EndPoint="250,90"></LineGeometry>-->
            </Path.Data>
            <Path.RenderTransform>
                <RotateTransform CenterX="250" CenterY="150" Angle="{Binding }"></RotateTransform>
            </Path.RenderTransform>
        </Path>
        <TextBox Height="43" HorizontalAlignment="Left" Margin="203,178,0,0" Name="textBox1" VerticalAlignment="Top" Width="91" TextChanged="textBox1_TextChanged" />
    </Grid>
</Window>




Thanks;

Is This A Good Question/Topic? 0
  • +

Replies To: How to bind this

#2 falcon eyes  Icon User is offline

  • D.I.C Head

Reputation: -4
  • View blog
  • Posts: 53
  • Joined: 16-April 07

Re: How to bind this

Posted 08 November 2011 - 06:38 AM

Pls some one help
Was This Post Helpful? -1
  • +
  • -

#3 ragingben  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 170
  • View blog
  • Posts: 637
  • Joined: 07-October 08

Re: How to bind this

Posted 10 November 2011 - 05:31 AM

If you aren't binding the windows DataContect to itself you can use this method to find the window, and then bind to the property:

Add namespace
xmlns:local="clr-namespace:CtrlTst"

Bind angle
<RotateTransform CenterX="250" CenterY="150" Angle="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:MainWindow}}, Path=Myangel, Mode=OneWay}"></RotateTransform>



I recommend (in general) binding the windows DataContext to the window itself then, as this simplifies most binding for a window. 90% of my windows are setup this way:
<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300" DataContext="{Binding RelativeSource={RelativeSource Self}}" Foreground="Blue">
    <Grid Background="{Binding Path=Foreground}"/>
</Window>


This post has been edited by ragingben: 10 November 2011 - 05:32 AM

Was This Post Helpful? 1
  • +
  • -

#4 falcon eyes  Icon User is offline

  • D.I.C Head

Reputation: -4
  • View blog
  • Posts: 53
  • Joined: 16-April 07

Re: How to bind this

Posted 13 November 2011 - 07:10 AM

thanks
I will try your suggestions
Was This Post Helpful? 0
  • +
  • -

#5 falcon eyes  Icon User is offline

  • D.I.C Head

Reputation: -4
  • View blog
  • Posts: 53
  • Joined: 16-April 07

Re: How to bind this

Posted 13 November 2011 - 07:30 AM

thank you it worked
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1