DropdownButton with TextBox?

4 posts, 1 answers
  1. Rayne
    Rayne avatar
    241 posts
    Member since:
    Sep 2010

    Posted 09 Jun 2011 Link to this post

    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).
  2. Answer
    Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 14 Jun 2011 Link to this post

    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. Rayne
    Rayne avatar
    241 posts
    Member since:
    Sep 2010

    Posted 14 Jun 2011 Link to this post

    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?

  5. Rayne
    Rayne avatar
    241 posts
    Member since:
    Sep 2010

    Posted 14 Jun 2011 Link to this post

    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.
Back to Top