Nested Property Value (Long Namespace Name)

7 posts, 1 answers
  1. Sayyed Hossein
    Sayyed Hossein avatar
    20 posts
    Member since:
    Oct 2012

    Posted 13 Oct 2012 Link to this post

    hi

    assume i have a property named MyProperty of type MyType with namespace address of :
    NameSpaceMain.Namespace2.Namespace3. ... .LastNameSpace.MyType


    as you know when using nested properties the value of the main property (who owns the nested properties) is shown somehow like this in tyhe propertygrid:


    + MyProperty                      NameSpaceMain.Namespace2.Namespace3. ... LastNameSpace.MyType
        nestedproperty1                  true
        nestedproperty2                  false
        nestedproperty3                  true
        nestedproperty4                  false

    what should i do to just show the last part (MyType) or even some other manual Name as the value of my property in the peopertygrid
    thank you in advance for your answer
  2. Answer
    Yoan
    Admin
    Yoan avatar
    1066 posts

    Posted 18 Oct 2012 Link to this post

    Hi,

     In order to achieve your goal you can override the ToString method of your "MyProperty" class like so:

    public override string ToString()
            {
                return String.Format( this.Namespace1.Namespace2.LastNamespace);
            }


    Please find attached sample project that meets your requirements.

    All the best,
    Yoan
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Sayyed Hossein
    Sayyed Hossein avatar
    20 posts
    Member since:
    Oct 2012

    Posted 20 Oct 2012 Link to this post

    thank you very much dear yoan for your helpful answer :)
  5. Andrei
    Andrei avatar
    1 posts
    Member since:
    Mar 2015

    Posted 28 Apr 2015 Link to this post

    Hey there,

     Regarding your answer: how can I make it so that the Header updates if the ToString method content changes?

     Thanks,

    Andrei

  6. Stefan X1
    Admin
    Stefan X1 avatar
    514 posts

    Posted 29 Apr 2015 Link to this post

    Hello Andrei,

    Basically, in such scenario the parent object needs to listen for a property change in its nested object. I have modified the sample project in a way that demonstrates how this can be achieved.

    I hope this helps.

    Best Regards,
    Stefan
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  7. rick
    rick avatar
    6 posts
    Member since:
    Jan 2016

    Posted 22 Mar in reply to Stefan X1 Link to this post

    Hi Stefan,

    Sorry for posting on an old thread. But I'm wondering is there a way to achieve this (just need display constant text) without overriding ToString() method?

  8. Stefan X1
    Admin
    Stefan X1 avatar
    514 posts

    Posted 24 Mar Link to this post

    Hello Rick,

    It is possible to bind a given PropertyDefinition to a particular property of an object. With such approach, however, the Nested properties will try to resolve their Binding within this particular property. You can take a look at the code snippet below, as an example.
    <telerik:PropertyDefinition DisplayName="Department"
                                Description="Department"
                                Binding="{Binding Department.Country}">
        <telerik:PropertyDefinition.NestedProperties>
            <telerik:PropertyDefinition DisplayName="Country"
                                        Binding="{Binding Country}"/>
            <telerik:PropertyDefinition DisplayName="ID"
                                        Binding="{Binding ID}"/>
        </telerik:PropertyDefinition.NestedProperties>
    </telerik:PropertyDefinition>

    With this setup, the PropertyDefinition's Binding will search for the Country and ID properties within the Country property. So, I suggest you sticking to the approach of overriding the ToString() method.

    Regards,
    Stefan X1
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top
UI for WPF is Visual Studio 2017 Ready