RadContextMenu on RadAutoCompleteBox

5 posts, 0 answers
  1. Joe Bohen
    Joe Bohen avatar
    62 posts
    Member since:
    May 2009

    Posted 27 Oct 2015 Link to this post

    Hi,

     I have attempted to add a RadContextMenu to a RadAutoCompleteBox but the context menu does not open when the RadAutoCompleteBox is clicked!  Can you see what my problem is please?

    Regards,

    Joe

     

    <telerik:RadAutoCompleteBox x:Name="ColDriverAutoBox" Grid.Column="3" Grid.Row="0" Padding="6,0,0,4" AutoCompleteMode="SuggestAppend" DropDownWidth="240" WatermarkContent="Enter Collection Driver name" TextSearchPath="Name"  SelectionMode="Multiple"  
    DisplayMemberPath="Code" SelectedItems="{Binding ColDrivers, Source={StaticResource ViewModel}}"            
    DropDownItemTemplate="{StaticResource CustomDropDownItemTemplate}" IsTabStop="True" TabIndex="141" ContextMenu="{x:Null}"  >
                                                        <telerik:RadContextMenu.ContextMenu>
                                                            <telerik:RadContextMenu >
                                                                <telerik:RadMenuItem Header="Copy" />
                                                                <telerik:RadMenuItem Header="Paste" />
                                                                <telerik:RadMenuItem Header="Cut" />
                                                                <telerik:RadMenuItem IsSeparator="True" />
                                                                <telerik:RadMenuItem Header="Select All" />
                                                            </telerik:RadContextMenu>
                                                        </telerik:RadContextMenu.ContextMenu>
                                                    </telerik:RadAutoCompleteBox>​

  2. Joe Bohen
    Joe Bohen avatar
    62 posts
    Member since:
    May 2009

    Posted 27 Oct 2015 in reply to Joe Bohen Link to this post

    I can see my error is by setting the context menu in the control rather than in the template so my question should really be how do I set it in the template so that it works when there is an item selected in the autocompletebox.  The Template:

     

    <DataTemplate x:Key="CustomDropDownItemTemplate">
                <Border BorderBrush="Gray" BorderThickness="1" Margin="2">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition/>
                            <RowDefinition/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>
                        <TextBlock Grid.Column="0" Grid.Row="0"
            Margin="5"
            FontWeight="Bold"
            Text="Name" />
                        <TextBlock Grid.Row="0" Grid.Column="1" Margin="0 5 0 0"
            Text=":"
            FontWeight="Bold"/>
                        <TextBlock Grid.Column="2" Grid.Row="0" Margin="5"
            Text="{Binding Name}" />
                        <Border BorderBrush="Gray" BorderThickness="0.5" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3"/>
                        <TextBlock Grid.Column="0" Grid.Row="2" Margin="5"
            FontWeight="Bold"
            Text="Code" />
                        <TextBlock Grid.Row="2" Grid.Column="1" Margin="0 5 0 0"
            Text=":"
            FontWeight="Bold"/>
                        <TextBlock Grid.Column="2" Grid.Row="2" Margin="5"
            Text="{Binding Code}" />
                    </Grid>
                </Border>
            </DataTemplate>​

  3. UI for WPF is Visual Studio 2017 Ready
  4. Nasko
    Admin
    Nasko avatar
    586 posts

    Posted 29 Oct 2015 Link to this post

    Hi Joe,

    We are not exactly sure that we completely understand the desired by you functionality. Would you like to apply RadContextMenu to the whole RadAutoCompleteBox or just for the items?

    From you initial post it seems you are trying to apply it to the control itself which is an appropriate approach. The reason why it does not get set as expected is because the WatermarkTextBox control that is placed inside RadAutoCompleteBox provides its own ContextMenu by default.

    So, one possible approach that we could suggest you in order to achieve the desired is by using the ChildrenOfType<T> to iterate through the visual tree of RadAutoCompleteBox and find the WatermarkTextBox. After that you need to set its ContextMenu property to null in order to disable the default native WPF ContextMenu and set the desired RadContextMenu.

    We have created a sample project that demonstrates the described above approach - please, check it and let us know if it worked for you. If not please, provide us some more information on when exactly you expect the menu to appear and where.
     
    Hope this helps.

    Regards,
    Nasko
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  5. Joe Bohen
    Joe Bohen avatar
    62 posts
    Member since:
    May 2009

    Posted 30 Oct 2015 in reply to Nasko Link to this post

    Hi Nasko,

    Thank you for your example app,  I am sorry my question is a little muddled but I would like to perform some actions on the selected items and not the whole RadAutoCompleteBox. 

    Regards,

    Joe

  6. Nasko
    Admin
    Nasko avatar
    586 posts

    Posted 02 Nov 2015 Link to this post

    Hi Joe,

    In order to apply RadContextMenu for the selected items you could customize the BoxesItemTemplate of RadAutoCompleteBox and place the desired RadContextMenu inside it. Please, check the following article from our help documentation concerning the BoxesItemTemplate and how to apply it:
    http://docs.telerik.com/devtools/wpf/controls/radautocompletebox/styles-and-templates/customizing-boxes-itemtemplate

    Attached you could also find a sample project that demonstrates how to apply RadContextMenu for the selected items.

    We hope this will help you.

    Regards,
    Nasko
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
Back to Top
UI for WPF is Visual Studio 2017 Ready