This is a migrated thread and some comments may be shown as answers.

how to find the control in radsplitbutton content template

13 Answers 134 Views
Buttons
This is a migrated thread and some comments may be shown as answers.
Gowd
Top achievements
Rank 1
Gowd asked on 13 Nov 2013, 10:53 AM


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 >

 

 

 

 

 

 

13 Answers, 1 is accepted

Sort by
0
Accepted
Tina Stancheva
Telerik team
answered on 18 Nov 2013, 12:59 PM
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 >>
0
Gowd
Top achievements
Rank 1
answered on 21 Nov 2013, 12:40 PM
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
0
Vladi
Telerik team
answered on 26 Nov 2013, 09:45 AM
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 >>
0
Gowd
Top achievements
Rank 1
answered on 28 Nov 2013, 05:32 AM
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.

0
Vladi
Telerik team
answered on 29 Nov 2013, 08:30 AM
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 >>
0
Gowd
Top achievements
Rank 1
answered on 09 Dec 2013, 09:09 AM
 Thank you.its helped me really.
0
Gowd
Top achievements
Rank 1
answered on 09 Dec 2013, 09:11 AM
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.

0
Pavel R. Pavlov
Telerik team
answered on 12 Dec 2013, 08:19 AM
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 >>
0
Gowd
Top achievements
Rank 1
answered on 12 Dec 2013, 08:42 AM
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.




















0
Pavel R. Pavlov
Telerik team
answered on 12 Dec 2013, 09:43 AM
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 >>
0
Gowd
Top achievements
Rank 1
answered on 12 Dec 2013, 11:41 AM
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?

0
Accepted
Pavel R. Pavlov
Telerik team
answered on 16 Dec 2013, 01:12 PM
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 >>
0
Gowd
Top achievements
Rank 1
answered on 19 Dec 2013, 05:00 AM
Hi Pavel,

Thanks its works fine.
Tags
Buttons
Asked by
Gowd
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Gowd
Top achievements
Rank 1
Vladi
Telerik team
Pavel R. Pavlov
Telerik team
Share this question
or