如何在我的 XAML 代码中设置 ComboBox 的默认选择?这就是我的 ComboBox 的代码:
<ComboBox Name="ComboBox1" Width="200" Height="30" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="10,10,0,0">
<ComboBoxItem>My first item</ComboBoxItem>
</ComboBox>
在我的 C# 代码中,我总是习惯这样设置 ComboBox 的默认值:
ComboBox1.SelectedIndex = 0;
是否可以在我的 XAML 代码中做同样的事情?
最佳答案
<ComboBox Name="ComboBox1" SelectedIndex="0" Width="200" Height="30" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="10,10,0,0">
<ComboBoxItem>My first item</ComboBoxItem>
</ComboBox>
希望对你有帮助
关于c# - 如何在我的 XAML 代码中设置默认的 ComboBox 选择?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11543193/