【问题标题】:scroll into the list that matches pressed key in the drop down滚动到下拉列表中与按下的键匹配的列表
【发布时间】:2020-02-17 04:56:01
【问题描述】:

我正在开发一个 UWP 应用,我有一个包含国家名称、国旗和国家代码列表的下拉列表。当我单击下拉列表时,国家列表打开。但是,如果我单击并按下任何字母(例如 I),它不会自动滚动到列表以 I 开头的列表。

我尝试将 IsTextSearchEnabled 属性添加到下拉列表中,但没有得到想要的结果。请谁能指导我这里需要做什么?

<ComboBox  x:Name="CmbCountrylist" Height="auto" IsEditable="True" 
IsTextSearchEnabled="True" Width="250" Margin="0,0,1,0" Background="red" 
PlaceholderText="Select Country" 
SelectionChanged="CmbCountryCodes1_SelectionChanged" 
HorizontalAlignment="Left" VerticalAlignment="Center">
<ComboBox.ItemTemplate>
<DataTemplate>


<StackPanel Orientation="Horizontal" ToolTipService.ToolTip="{Binding name}" >

<Image x:Name="ImgFlag" Width="16"  Height="16" Margin="0,2,5,2" VerticalAlignment="Center" HorizontalAlignment="Left" Source="{Binding ImagePath}" />

<TextBlock x:Name="txtCountryName" Text="{Binding name}" />
<TextBlock x:Name="txtCode" Text="{Binding dial_code}" />
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>          
<ComboBox.ItemsPanel>         
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical" />
</ItemsPanelTemplate>                                
</ComboBox.ItemsPanel>  

</ComboBox>                      

【问题讨论】:

    标签: c# xaml uwp combobox


    【解决方案1】:

    根据您的描述,绑定的数据源是一个类。在这种情况下,请覆盖类的ToString() 方法以返回国家/地区名称。

    public class Country
    {
       // other properties
    
       public override string ToString()
       {
           return name;
       }
    }
    

    当您在ComboBox 中输入文本时,ComboBox 将匹配数据列表中的数据,但ComboBox 不会主动查找该类的属性,而是查找该类的值ToString() 方法。

    最好的问候。

    【讨论】:

    • 如果答案已经解决了您的问题,请mark 它被稍后访问此主题的方便人士所接受
    猜你喜欢
    • 1970-01-01
    • 2023-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-19
    • 2014-05-22
    相关资源
    最近更新 更多