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

AutoCompleteBox SelectedItem binding to textbox visibility

1 Answer 88 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
ali
Top achievements
Rank 1
ali asked on 26 Jan 2019, 11:21 AM

Hello,

How can i bind visibility property of a textbox to  a selecteditem of AutocompleteBox (with NullToVisibilityConverter) in Wpf? This code dont work.

......

.....

 <telerik:RadButton Grid.Column="1"
                                                   HorizontalAlignment="Right"
                                                   Visibility="{Binding Path=SelectedItem, ElementName=RadAutoCompleteBox1, Converter={StaticResource NullToVisibilityConverter}}"
                                                   Command="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=UserControl}, Path=DataContext.Add}"
                                                   CommandParameter="{Binding Path=.}">
                                    <Image Source="{framework:ApplicationImage ImageX}" Height="16" Width="16"/>
                                </telerik:RadButton>

....

....

 

 <telerik:GridViewDataColumn.CellEditTemplate>
                        <DataTemplate >
                            <telerik:RadAutoCompleteBox DisplayMemberPath="Name"
                                                        TextSearchMode="Contains"
                                                        SearchText="{Binding Path=Name, Mode=TwoWay}"
                                                        AutoCompleteMode="Suggest"
                                                        SelectionMode="Single"        
                                                        VerticalAlignment="Center"
                                                        BoxesItemStyle="{StaticResource RadAutoCompleteBoxStyle}"
NoResultsContentTemplate="{StaticResource
RadAutoCompleteBoxNoResultsContentTemplate}"
                                                        NoResultsContent="{x:Static resources:Translations.lbl_NoMatches}"
ItemsSource="{Binding Path=DataContext.Project.Names,
RelativeSource={RelativeSource AncestorType=telerik:RadGridView}}">

                                <i:Interaction.Triggers>
                                    <i:EventTrigger EventName="LostFocus">
<i:InvokeCommandAction 
Command="{Binding RelativeSource={RelativeSource FindAncestor,
AncestorType=UserControl},
Path=DataContext.NewNameEnteredCommand}"
                                                                CommandParameter="{Binding Path=.}"/>
                                    </i:EventTrigger>
                                </i:Interaction.Triggers>
                            </telerik:RadAutoCompleteBox>
                        </DataTemplate>

                    </telerik:GridViewDataColumn.CellEditTemplate>

1 Answer, 1 is accepted

Sort by
0
Dinko
Telerik team
answered on 30 Jan 2019, 01:14 PM
Hello Ali,

Thank you for the provided code snippet.

If I have correctly understood your approach you want to bind a button outside of the RadGridView to the RadAutoCompleteBox in the cell. The tricky part here is that the RadAutoCompleteBox is visible when the cell is in edit mode. What you could try is to subscribe to the BeginningEdit and CellEditEnded. In the BeginningEdit event handler, you can bind the currently loaded RadAutoCompleteBox SelectedItem property to the Visibility of the RadButton.  And in the CellEditEnded hide the button when the cell edit mode ended. Check the attached project which demonstrates this. When you run the project click on the second column cell to go to edit mode. Then type London and remove it. Observed that the button at the bottom right corner appears and disappear. Hope this solution will work in your main application.

Regards,
Dinko
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
AutoCompleteBox
Asked by
ali
Top achievements
Rank 1
Answers by
Dinko
Telerik team
Share this question
or