locked
Binding the Data Property of the Path Element RRS feed

  • Question

  • I have an app in which I am using 3 Path elements with the same values for their Data property. I figured the best way to do this would be to bind the property as follows:

    Data="{Binding Data,ElementName=Path1}"

    However, this does not seem to be working. However, if I manually enter the Data property, it works fine. Is there a rule against binding the Data property? Is there a better way to synchronize the Data property of multiple Path elements? Thanks.


    Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

    Friday, December 6, 2013 10:01 PM

Answers

  •  Hi Nathan,

    The actual Data property is read/write, but it takes a Geometry, not a string.  you can also try below code in code behand

     <StackPanel x:Name="contentPanel">
                <Path x:Name="path" Data="{Binding Data}"  Fill="Azure"/>
                <Path x:Name="path1"  Data="{Binding Data}"  Fill="Red"/>
                <Path x:Name="path2"  Data="{Binding Data}"  Fill="Green"/> 
                <Path x:Name="path3"  Data="{Binding Data}" Fill="Blue"/>
            </StackPanel>

    public class PathData
        {
            private string _data;
            public string Data
            {
                get { return _data; }
                set { _data = value; }
            }
        }

     

    PathData testData = new PathData();
    testData.Data = string.Format("M 100,200 C 100,25 400,350 400,175 H 280");     
      contentPanel.DataContext = testData;

    Regards,

    Jenny

     

    Thursday, December 26, 2013 9:51 AM

All replies

  • Hi Nathan,

    I can also reproduce this, the error message says "The parameter is incorrect."

    It seems to be a bug, I will ask some senior engineers to look for you, and please be patient.

    Thank you.

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.


    Monday, December 9, 2013 3:32 AM
    Moderator
  • Hi there,

    try below code, if you would like do to binding in xaml, then perhaps you need to write a value converter .

    <!--<Path x:Name="path" Data="M 100,200 C 100,25 400,350 400,175 H 280" Fill="Azure">-->
            <StackPanel>
                <Path x:Name="path1" Fill="Red"/>
                <Path x:Name="path2" Fill="Green"/>
                <Path x:Name="path3" Fill="Blue"/>

            </StackPanel>

     var b = new Binding
                {
                    Source = "M 100,200 C 100,25 400,350 400,175 H 280"
                };
               
                BindingOperations.SetBinding(path1, Windows.UI.Xaml.Shapes.Path.DataProperty, b);
                BindingOperations.SetBinding(path2, Windows.UI.Xaml.Shapes.Path.DataProperty, b);
                BindingOperations.SetBinding(path3, Windows.UI.Xaml.Shapes.Path.DataProperty, b);

    Regards,

    Jenny


    • Edited by JennyLi-MSFT Wednesday, December 25, 2013 9:32 AM
    Wednesday, December 25, 2013 9:31 AM
  • That would probably be OK if I was doing everything in the codebehind, but I am just trying to get my Path elements to have the same Data using just XAML. My goal is to synchronize the Path elements' Data properties without needing to add codebehind for every group of Paths, and to only need to give a Name to one of the Paths so that I can use binding for the others. With your idea, I may as well just set the value directly. Any other ideas? Thanks.

    Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/

    Wednesday, December 25, 2013 5:11 PM
  •  Hi Nathan,

    The actual Data property is read/write, but it takes a Geometry, not a string.  you can also try below code in code behand

     <StackPanel x:Name="contentPanel">
                <Path x:Name="path" Data="{Binding Data}"  Fill="Azure"/>
                <Path x:Name="path1"  Data="{Binding Data}"  Fill="Red"/>
                <Path x:Name="path2"  Data="{Binding Data}"  Fill="Green"/> 
                <Path x:Name="path3"  Data="{Binding Data}" Fill="Blue"/>
            </StackPanel>

    public class PathData
        {
            private string _data;
            public string Data
            {
                get { return _data; }
                set { _data = value; }
            }
        }

     

    PathData testData = new PathData();
    testData.Data = string.Format("M 100,200 C 100,25 400,350 400,175 H 280");     
      contentPanel.DataContext = testData;

    Regards,

    Jenny

     

    Thursday, December 26, 2013 9:51 AM