using autocomplete box in silverlight?

浪尽此生 提交于 2019-12-12 17:04:50

问题


i am currently displaying data in the radgrid controls of telerik, i want to add an autotextbox over the column named "Name". how can i do this?

my radgrid only displays data and i want that whenever user enters into textbox a list of name pops up just like in stackoverflow web site.

please help..i have been using silverlight,wcf ria services,telerik controls.


回答1:


You can use the AutoComplete textbox from the Silverlight 4 Toolkit. The toolkit is an advanced set of controls that are not part of the core Visual Studio library. To download & install, you can head here. Once you have it installed, you add a project reference to System.Windows.Controls add this to your UserControl declaration:

xmlns:input="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input"

This gives you a reference point for the Silverlight Toolkit, specifically the input controls. Once that's done, here is an example of using the autocomplete textbox:

<input:AutoCompleteBox IsTextCompletionEnabled="False" HorizontalAlignment="Left" ItemsSource="{StaticResource SampleEmployees}" SelectionChanged="OnSelectionChanged"/>

This comes directly from the documentation from the Silverlight Toolkit. Link here. Click the 'AutoCompleteBox' in the left menu (under heading: Input). Once loaded, you can view the XAML/C# by clicking on any one of the items at the bottom of the window, such as 'AutoCompleteBoxSample.xaml' or 'AutoCompleteBoxSample.xaml.cs' This should give you the start/code you're looking for.

In your case, you'll also need to create a cell template for the radgridview. Here's a quick sample of what that might look like:

<radControls:RadGridView x:Name="registerGridView" 
                             AutoGenerateColumns="False">  
        <radControls:RadGridView.Columns> 
            <radControls:GridViewToggleRowDetailsColumn /> 
            <radControls:GridViewDataColumn Header="Client" /> 
            <radControls:GridViewDataColumn Header="Site" />  
            <radControls:GridViewDataColumn Header="Name">  
                <radControls:GridViewDataColumn.CellTemplate> 
                    <DataTemplate> 
                        <StackPanel Orientation="Horizontal">  
                            <input:AutoCompleteBox HorizontalAlignment="Left" ItemsSource="{Binding Names}" SelectionChanged="OnSelectionChanged"/>
                        </StackPanel> 
                    </DataTemplate> 
                </radControls:GridViewDataColumn.CellTemplate> 
            </radControls:GridViewDataColumn> 
        </radControls:RadGridView.Columns> 
    </radControls:RadGridView> 


来源:https://stackoverflow.com/questions/5871918/using-autocomplete-box-in-silverlight

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!