无法将 SelectedIndex 设置为 0 [英] Cannot set SelectedIndex to 0

查看:32
本文介绍了无法将 SelectedIndex 设置为 0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当尝试将 ComboBox SelectedIndex 设置为 0 时,我将第一个值设为默认值,但不起作用,默认情况下组合框为空.如果我尝试将其设置为任何其他有效数字,我会将所选索引作为默认值.

When trying to set a ComboBox SelectedIndex to 0 so I have the first value as default, doesn't work, the combobox its empty by default. If I try setting it to any other number it works, I have the selected index as a default value.

有人知道为什么我不能从 xaml 将它设置为 0 吗?

Anyone have an idea why I can't set it to 0 from xaml ?

<RSControls:SmoothScrollComboBox
    Grid.Column="1"
    x:Name="comboTypes"
    Margin="7,0,0,0"
    SelectedValue="{Binding Path=SelectedTypes}"
    SelectedValuePath="Name"
    SelectedIndex="0"
    ItemsSource="{Binding Source={StaticResource GroupedTypes}}"
    DisplayMemberPath="Display"
    SelectionChanged="comboTypes_SelectionChanged"
    IsSynchronizedWithCurrentItem="True">

PS:忘了说我有2个comboboxes,另一个工作,实现方式相同,只有Selectedvalue和ItemSource不同.

PS: forgot to mention that I have 2 comboboxes, the other one works, implemented in the same way, only the Selectedvalue and ItemSource differs.

推荐答案

这可能是因为您将所选项目设置了两次:一次使用 SelectedIndex,一次使用 SelectedValue

It's probably because you are setting the selected item twice: once with SelectedIndex and once with SelectedValue

删除 SelectedValue 属性,SelectedIndex 应该可以工作

Remove the SelectedValue property and SelectedIndex should work

这篇关于无法将 SelectedIndex 设置为 0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆