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

DropdownButton with TextBox?

3 Answers 516 Views
Buttons
This is a migrated thread and some comments may be shown as answers.
Rayne
Top achievements
Rank 1
Rayne asked on 09 Jun 2011, 05:59 PM
I'm using a drop down button to display a context menu of options. But I'd like the content of the button to appear as a TextBox (like an editable combobox, but read-only). Is this possible?

If not, can I at least left align the text that gets displayed? I'm using a ContentTemplate and setting HorizontalAlignment and TextAlignment to Left on the TextBlock, but it still is aligning to the center of the control.

Essentially I want it to look like an editable combobox (with a textbox and dropdown button to the side; textbox can look disabled/read-only).

3 Answers, 1 is accepted

Sort by
0
Accepted
Tina Stancheva
Telerik team
answered on 14 Jun 2011, 06:11 PM
Hi Rayne,

In the RadDropDownButton you need to set the HorizontalContentAlignment and VerticalContentAlignment properties to stretch the Content.

Also, I am not sure whether your requirements allow using the RadComboBox but it implements this functionality out-of-the-box.

I attached a sample project that illustrates how to implement your scenario both with the RadDropDownButton and the RadComboBox. I hope it helps.

Best wishes,
Tina Stancheva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Rayne
Top achievements
Rank 1
answered on 14 Jun 2011, 06:43 PM

Here is my code:

<telerik:RadDropDownButton HorizontalContentAlignment="Left" Grid.Row="0" Grid.Column="1" Margin="3"
      Content="{Binding Person.FullName, UpdateSourceTrigger=PropertyChanged, Mode=OneWay}"
       ContentTemplate="{StaticResource DropDownContentTemplate}" Name="AirAssignmentDropDown" CloseOnEnter="True">
   <telerik:RadDropDownButton.DropDownContent>
     <telerik:RadContextMenu ItemClick="AssignedToAir_ItemClick">
     <telerik:RadMenuItem Header="Assign Air Media" Command="{Binding AssignMedia}" CommandParameter="1" />
     <telerik:RadMenuItem Header="Clear Assigned To for Air" Command="{Binding ClearAssignedTo}" CommandParameter="1" />
     </telerik:RadContextMenu>
    </telerik:RadDropDownButton.DropDownContent>
 </telerik:RadDropDownButton>

My Data Template is defined as <TextBox Text="{Binding}" IsReadOnly="True" />

Why would this cause an exception in the designer?

System.Reflection.TargetInvocationException

Does it make a difference that my DropDown Content is a Context menu rather than a listbox?

0
Rayne
Top achievements
Rank 1
answered on 14 Jun 2011, 07:03 PM
I finally got to look how I wanted. I had to declare OneWay binding on the textbox in the data template. Which is fine since it's supposed to be readonly and I set the value on the bound property.
Tags
Buttons
Asked by
Rayne
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Rayne
Top achievements
Rank 1
Share this question
or