A stupid question: How to set the property's property of an Xaml element? RRS feed

  • Question

  • Hi, guys, long time no see! Recently I'm busy creating a custom Chart control using UserControl. Everything is ok until I was stucked on a stupid problem--I just can't set the property of the Axis of the my Chart. Here is my code:


        <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
            <local:MyChart >
                <!--this won't work-->
                <local:MyChart.Axis  SomeProperty="0"/>
                <!--this won't work either-->
                <local:MyChart.Axis2  SomeProperty="0" />


    using Windows.UI.Xaml;
    using Windows.UI.Xaml.Controls;
    namespace App28
        public class MyChart: UserControl
            public BottomAxis Axis
                get { return (BottomAxis)GetValue(AxisProperty); }
                set { SetValue(AxisProperty, value); }
            public static readonly DependencyProperty AxisProperty =
                DependencyProperty.Register("Axis", typeof(BottomAxis), typeof(MyChart), new PropertyMetadata(null));
            public BottomAxis Axis2 { get; set; }
        public class BottomAxis : FrameworkElement
            public int SomeProperty { get; set; }
        public sealed partial class MainPage : Page
            public MainPage()

    btw: When would WinRT supply a standard Chart control? It's so painful to write one from scratch. And it's a small project, I can not afford a third-party control collection.

    Monday, December 16, 2013 3:34 PM


All replies

  • I moved this to the correct forum for you. The UI design forum is for discussing how the app should look, not how to implement the app. We cannot comment on future features, but I believe there are free chart controls available.

    Monday, December 16, 2013 4:07 PM
  • Hi, Rob,  thanks for your kindness! I didn't realize I am in UI design forum.

    Would you like to shed some light on my stupidest question? Really stuck here. 

    Best regards!

    Monday, December 16, 2013 4:25 PM
  • I'm not where I can look at it now. I moved it to where somebody else can help.


    Monday, December 16, 2013 4:32 PM
  • Hi Silverbird,

    you need to explicitly create a BottomAxis-object:

                    <local:BottomAxis SomeProperty="5"/>
                    <local:BottomAxis SomeProperty="5"/>

    You could also create a TypeConverter-subclass for the BottomAxis-Type that would allow you setting the Axis-Property like that:

    <local:MyChart Axis="5"/>

    @Rob: Great teamwork. ;-)

    Thomas Claudius Huber

    "If you can't make your app run faster, make it at least look & feel extremly fast"

    My latest app: The "Womanizer" :-)
    twitter: @thomasclaudiush
    homepage: www.thomasclaudiushuber.com
    author of: ultimate Windows Store Apps handbook | ultimate WPF handbook | ultimate Silverlight handbook

    Monday, December 16, 2013 4:45 PM
  • Hi, Thomas, thanks for the quick reply.

    I've tested the first solution, and it works great.

    Many thanks!

    Monday, December 16, 2013 5:20 PM