DataFilter DataTemplate

6 posts, 0 answers
  1. WILLIAM
    WILLIAM avatar
    134 posts
    Member since:
    Jun 2012

    Posted 21 Jun 2012 Link to this post

    I'm a little confused on how to create a data template in code (not xaml).  I'm wanting to use a combo box.  I have created my own class that inherits from DataTemplateSelector, and in this class, I create as many DataTemplate properties as I need.  What I can't seem to figure out is where to specify the type of control.  I'm trying DataTemplate.Type = typeof(RadComboBox), but in the EditorCreated event, it's still a TextBox.

    Where do I specify the type of editor?

    i.e.  I want to be able to do the following, but in the codebehind:

    <!--EditorTemplate for the Name property.-->
    <DataTemplate x:Key="NameFilterEditorTemplate">
    <telerik:RadComboBox SelectedValue="{Binding Value, Mode=TwoWay, FallbackValue=null}"
    MinWidth="100"/>
    </DataTemplate>

    Thanks!
  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 22 Jun 2012 Link to this post

    Hi,

     Have you already checked this help article?

    Regards,
    Didie
    the Telerik team

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

  3. DevCraft banner
  4. WILLIAM
    WILLIAM avatar
    134 posts
    Member since:
    Jun 2012

    Posted 22 Jun 2012 Link to this post

    Yes I have, but it doesn't give any examples of what I'm trying to do.  In the xaml there is the code example below.  But I want to do this in code behind, not in the xaml.  Can you point me to an example

    <DataTemplate x:Key="ComboBoxEditor">
           <telerik:RadComboBox SelectedValue="{Binding Value, Mode=TwoWay, FallbackValue=null}" MinWidth="100" />
    </DataTemplate>
  5. WILLIAM
    WILLIAM avatar
    134 posts
    Member since:
    Jun 2012

    Posted 22 Jun 2012 Link to this post

    I'm slowly getting through this, but it does seem to be working.  So let me ask this one question to see if understand correctly how this is supposed work.

    When EditorSelector.SelectTemplate is called, I loop through the rules and if I find a match, I return the DataTemplate from that rule.  Is that correct?

    Assuming that the data template I return is of the correct type (in my case a RadComboBox) when the EditorCreated event is fired, shouldn't the Editor be of type RadComboBox?

    I have my rules setup, and when debugging, the SelectTemplate method returns a combobox correctly, but when the EditorCreated event is fired, the editor is a TextBox.

    Can anyone help me understand the disconnect that I seem to be having?

    public override DataTemplate SelectTemplate(object item, DependencyObject container)
            {
                var ipd = item as ItemPropertyDefinition;
                if (ipd == null) return base.SelectTemplate(item, container);
     
                foreach(var etr in EditorTemplateRules)
                {
                    //this if statement works correctly and returns a RadComboBox when needed
                    if (etr.PropertyName == ipd.PropertyName) return etr.DataTemplate;
                }
     
                return base.SelectTemplate(item, container);
            }
     
    private void DataFilterEditorCreated(object sender, EditorCreatedEventArgs e)
    {
          var rcb = ((RadComboBox) e.Editor);            //e.Editor is always a TextBox
  6. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 27 Jun 2012 Link to this post

    Hello,

    Can you please send us a very small runnable dummy project which demonstrates the behavior you are faced with. We will take a look to see what is going on.

    Thanks in advance.

    Greetings,
    Ross
    the Telerik team

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

  7. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 27 Jun 2012 Link to this post

    Hi,

     Would it be possible for you to isolate the problem you have met in a demo project and send it to us? That way we could explain better.

    Greetings,
    Didie
    the Telerik team

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

Back to Top
DevCraft banner