PropertyGrid AutoGeneratePropertyDefinitions=true

5 posts, 0 answers
  1. Mahesh
    Mahesh avatar
    3 posts
    Member since:
    Jun 2011

    Posted 31 Jan 2012 Link to this post

    I am trying to use a PropertyGrid for setting properties of various object types.
    My requirement is that for a given property, I should be able to select Value from the RadComboBox and set it on the property of a given object.
    I dont want to assign it based on ProprtyName and hardcode it in event handler, so I am setting custom attributes on properties and using them to assign perticular template for a given attribute.
    I have defined the DataTemplate in xaml and assining it in codebehind in AutoGeneratingPropertyDefinition event handler.

    I want to use same template for different properties might be with some slight change. i.e. Onlt SelectedValue path has to be changed in a below template.

    <DataTemplate x:Key="DataProviderTemplate"> 
     <telerik:RadComboBox ItemsSource="{Binding Source={StaticResource DataContextProxy}, Path=DataSource.DataSources}"  DisplayMemberPath="Name" SelectedValuePath="Name"  SelectedValue="{Binding Path=PermissionedUserSearchTextBoxDPName, Mode=TwoWay}" Margin="2,0,0,0" VerticalAlignment="Center">  </telerik:RadComboBox>

    </DataTemplate>

    CodeBehind in event handler is
    DataTemplate dt = LayoutRoot.Resources["DataProviderTemplate"] as DataTemplate; 

    e.PropertyDefinition.EditorTemplate = dt;

    But I am facing issue of binding PropertyValue in the template.

    I also tried changing RadComboBox.SelectedValue's binding path in template using code behind, but it is of not much help.

    Please advice.

     

     

  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 01 Feb 2012 Link to this post

    Hi Mahesh,

    Everything seems correctly set in the code-snippets you provided. Can you provide a bit more details what is the exact behavior that you experience - is the source not available, is the selected value not selected initially ? Can you select an item afterwards ? 

    Kind regards,
    Maya
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft banner
  4. Mahesh
    Mahesh avatar
    3 posts
    Member since:
    Jun 2011

    Posted 01 Feb 2012 Link to this post

    Maya - Code given in#1 work for given single property.
    But in the given code, at runtime, I want to set Path for each property. I dont want to have seperate template for each property which is autogenerated.
    SelectedValue="{Binding Path=City1, Mode=TwoWay}"

    My requirement is, I want to set property from the given options in dropdown. Say I have 3 properties like City1, Ciity2, and City3. For all these 3 properties, I want to set city name from a dropdown
    i,e City1= New york, City2=Boston, City3=Mumbai. All these cities are to be selected from dropdown showing all cities.
    City1 => Select from city combobox ( list of US cities)
    City2 => Select from city combobox ( list of US cities)
    City3 => Select from city combobox ( list of US cities)
    Once selected in dropdown the property value should be set & dispalyed in combobox.

    I am open for any option that will
    1. Single EditTemplate that can be used for all these 3 properites
    2. Allow me to use my own list of Cities that is in ViewModel which is binded to UserControl that holds PropertyGrid.

    Currently I am using one single template for all these 3 properties, but its not helping due to hardcoded path.

    hope this helps.
  5. Mahesh
    Mahesh avatar
    3 posts
    Member since:
    Jun 2011

    Posted 02 Feb 2012 Link to this post

    telerik support - any inputs on above issue??
  6. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 06 Feb 2012 Link to this post

    Hi Mahesh,

    We will introduce a new feature for defining a data template for different properties in our next official release Q1 2012 (it will be available in the middle of February). Thus you will be able to achieve your scenario just by using the attached behavior (AutoBindBehavior). Once the release is available, you will be able to find an example in our demos as well.  

    Greetings,
    Maya
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Back to Top
DevCraft banner