AutoCompleteBox SelectedItem binding to textbox visibility

2 posts, 0 answers
  1. ali
    ali avatar
    5 posts
    Member since:
    Jan 2019

    Posted 26 Jan Link to this post

    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>

  2. Dinko
    Admin
    Dinko avatar
    955 posts

    Posted 30 Jan Link to this post

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