how to find the control in radsplitbutton content template

14 posts, 2 answers
  1. Gowd
    Gowd avatar
    13 posts
    Member since:
    Nov 2013

    Posted 13 Nov 2013 Link to this post


    hi telerik,

    please help me to find the control name in the content template of radsplitbuton.

    <
    shared:SRadSplitButton x:Name="SplitButton" >

    <shared:SRadSplitButton.ContentTemplate>

    <DataTemplate>

    <shared:SRadWatermarkTextBox Name="otherNumberTb">

    </DataTemplate>

    </shared:SRadSplitButton.ContentTemplate

     

     

    >
    </

    shared:SRadSplitButton

     

    >

    and the below also tried

    <shared:SRadSplitButton x:Name="SplitButton" >

    <shared:SRadSplitButton.ContentTemplate>

    <DataTemplate>

    <shared:SRadWatermarkTextBox x:Name="otherNumberTb">

    </DataTemplate>

    </shared:SRadSplitButton.ContentTemplate>
    </shared:SRadSplitButton >

     

     

     

     

     

     

  2. Answer
    Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 18 Nov 2013 Link to this post

    Hi Gowd,

    You can get the content of a DataTemplate using the LoadContent() method as it creates the UIElements in the DataTemplate.

    You can also use the Telerik ChildrenOfType<T>() extension method that traverses the visual tree down to find a collection of children of type T.

    For instance in the RadSplitButton Click event handler you can try either of the following:
    private void SplitButton_Click(object sender, RoutedEventArgs e)
    {
        RadWatermarkTextBox watermark = (sender as RadSplitButton).ChildrenOfType<RadWatermarkTextBox>().FirstOrDefault();
        RadWatermarkTextBox watermarkContent = (sender as RadSplitButton).ContentTemplate.LoadContent() as RadWatermarkTextBox;
    }

    Regards,
    Tina Stancheva
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. DevCraft banner
  4. Gowd
    Gowd avatar
    13 posts
    Member since:
    Nov 2013

    Posted 21 Nov 2013 Link to this post

    Hi Tina Stancheva ,

    Firstly tanx for ur reply.

    and its works very well.

    And I have one more doubt related to combobox.

    I have a list of items In the combobox.

    I want to put the button(new) in combox to create the new item.

    could you please tel me if you have any sample or idea about the same.


    Regards,
    Sai
  5. Vladi
    Admin
    Vladi avatar
    744 posts

    Posted 26 Nov 2013 Link to this post

    Hi,

    In order to add customizations to the template of the control you will need to customize its Template, EditableTemplate or NonEditableTemplate depending on the mode in which you are using the control. You can customize that ControlTemplate it to the desired extend and add a button that will add new items to the collection bound to the ItemsSource of the control. The next code snippet shows how to add a new Item to the collection from the code behind:
    <telerik:RadComboBox ItemsSource="{Binding Items}"
                        x:Name="ComboBox"
                        DisplayMemberPath="Name"/>


    private void AddNewItem()
    {  
        var newItem = new Item() { Name = "New Item" };
        var newItemsSource = this.ComboBox.ItemsSource as IList<Item>;
        newItemsSource.Add(newItem);
        this.ComboBox.ItemsSource = newItemsSource;
    }

    Hope this is helpful.

    Regards,
    Vladi
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  6. Gowd
    Gowd avatar
    13 posts
    Member since:
    Nov 2013

    Posted 27 Nov 2013 Link to this post

    HI,

    This is exactly not matching to my requirement.

    in the listbox we have a button like clearselecteditem button.in the place of that button I want to display the "New".

    this I can do by setting clearselectionbuttoncontent="New"

    but my requirement is when I click this button I need to do some actions in my code.So I want to set my own command to that button.

    Please help me on this way.

  7. Vladi
    Admin
    Vladi avatar
    744 posts

    Posted 29 Nov 2013 Link to this post

    Hello,

    In order to change the default behavior of the ClearButton in the RadComboBox control you will need to customize the NonEditableTemplate or EditableTemplate of the RadComboBoxStyle depending on the mode in which you are using the control in. In those ControlTemplates you will need to find the RadButton controls with x:Name="PART_ClearButton", remove that name in order to remove the selection clearing behavior and add a Click event in which handle the adding of new items. The easiest approach when customizing the built-in Telerik themes is with the use of Implicit Styles.

    Hope this is helpful.

    Regards,
    Vladi
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  8. Gowd
    Gowd avatar
    13 posts
    Member since:
    Nov 2013

    Posted 09 Dec 2013 Link to this post

     Thank you.its helped me really.
  9. Gowd
    Gowd avatar
    13 posts
    Member since:
    Nov 2013

    Posted 09 Dec 2013 Link to this post

    In the same control.i have below issues. xaml code is below for that.

    <telerik:RadSplitButton.ContentTemplate>

    <DataTemplate>

    <telerik:RadWatermarkTextBox/>

    </DataTemplate>

    </telerik:RadSplitButton.ContentTemplate>

    in the radawatermarktextbox which is located in the datatemplate->content template the space bar is not functioning properly.
    when I click on space bar its not effecting in the  text.if I hold the spacebar then its starting moving.

    please help me out on this.

  10. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1183 posts

    Posted 12 Dec 2013 Link to this post

    Hello Gowd,

    Thank you for contacting us on that matter. We clearly understand your scenario. Unfortunately, the same scenario using the native controls is also working as you report. Please take a look at the attached project demonstrating my point.

    However, if you provide us with more information regarding your requirements we may be able to suggest using another set of our controls to achieve them.

    Thank you for your cooperation.

    Regards,
    Pavel R. Pavlov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  11. Gowd
    Gowd avatar
    13 posts
    Member since:
    Nov 2013

    Posted 12 Dec 2013 Link to this post

    Hi pavel,

    Thanks for your quick reply.

    it seems i didn't explain my issue clearly.

    the project what u attached its not matching my requiremnt.

    the below is your code

     <Grid x:Name="LayoutRoot" Background="White">
            <StackPanel>
                <telerik:RadSplitButton Height="30">
                    <telerik:RadSplitButton.ContentTemplate>
                        <DataTemplate>
                              <telerik:RadWatermarkTextBox HorizontalAlignment="Stretch" WatermarkContent="Search" />  
                        </DataTemplate>
                    </telerik:RadSplitButton.ContentTemplate>
                </telerik:RadSplitButton>

                <Button>
                    <Button.ContentTemplate>
                        <DataTemplate>
                            <TextBox />
                        </DataTemplate>
                    </Button.ContentTemplate>
                </Button>
            </StackPanel>

    you do the test with below steps

    enter "sometext" in the radwatermarktextbox which is in the content template of radsplitbutton.

    here now i want to give one space in beteen the "Some" and "text".

    but the space bar click is not working in the radwatermarktextbox which is in the content template of radsplitbutton.


    Please check with above scanrio.




















  12. Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1183 posts

    Posted 12 Dec 2013 Link to this post

    Hi Gowd,

    I understand your scenario and you are right for the behavior - you cannot enter a space inside the RadWatermarkTextBox when it is hosted inside the ContentTemplate of the RadSplitButton. The reason for this behavior is the fact that the button handles the key down event and the space will normally open its DropDown part or press it (if normal button is used).

    However, please note that the controls that Microsoft designed behave the same way (this is why i sent you the project). Sine, we are working with them we try to follow their patterns and practices. This is why it is expected that the TextBox controls will not receive the space key.

    I asked you to elaborate more on your requirements because it is not a usual scenario to host a TextBox inside a button. Actually you are the firs one requesting this as far as I remember.

    If you provide us with more details about your scenario we might be able to suggest better approach. Thank you for your cooperation.

    Regards,
    Pavel R. Pavlov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  13. Gowd
    Gowd avatar
    13 posts
    Member since:
    Nov 2013

    Posted 12 Dec 2013 Link to this post

    Hi pavel,

    thanks for your quick response.

    I will tel you my requirement.

    I have one list of record in database.

    I want to bind those list to combobox .and at the same time in the combobox dropdown I have to display the button "New" at bottom level.and  and I will bind the first record as the selecteditem in the combobox.

    here if I click on "new" button I have to create the item in the combox and cursur should be in the combox item to enter the text.

    this requirement I unable to implement with combobx.

    so I went with splitbutton.

    and in the dropdowncontent I kept one listbox and one button.listbox with list of records and new button to create the item.this is fine.

    and I will take the first record as selecteditem for splitbutton.

    so far I have done.now here my requirement is what ever the item I selected I have to edit that.

    so I kept watermarktextbox inside the content template of radsplitbutton. so I can edit the selecteditem.

    here why I used watermark is I don't have label/textblock to identity the control so watermarkcontent solves that.

    I reached my all the requirement now the issue is I cant give space in between the text which is  binded to watermarktextbox.




    please let me know if you have nay confusion on my requirement.


    and telerik have any online chat support for quick response?

  14. Answer
    Pavel R. Pavlov
    Admin
    Pavel R. Pavlov avatar
    1183 posts

    Posted 16 Dec 2013 Link to this post

    Hi Gowd,

    In your particular case you can try to subscribe to the KeyDown event of the RadWatermarkTextBox control. In its handler you will be able to check if the pressed key is space you will be able to implement custom logic for updating the Text of the RadWatermarkTextBox. By doing so you will be able to achieve your requirement. You can use similar to this logic:

    private void MyRadWatermarkTextBox_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.Key == Key.Space)
        {
            var start = (sender as TextBox).SelectionStart;
            (sender as TextBox).Text = (sender as TextBox).Text.Insert(start, " ");
            (sender as TextBox).SelectionStart = start+1;
        }
    }

    The reason for this workaround is the fact that the button part of the RadSplitButton is actually RadButton which derives from the native Button component. And the native component handles the space key (activates the click of the button). You will have to keep in mind this behavior then you work with the Button component.

    I hope this will help you.

    Regards,
    Pavel R. Pavlov
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  15. Gowd
    Gowd avatar
    13 posts
    Member since:
    Nov 2013

    Posted 18 Dec 2013 Link to this post

    Hi Pavel,

    Thanks its works fine.
Back to Top
DevCraft banner