当数据可用时,Comboxbox 自动选择第一项 [英] Comboxbox auto select first item when data is available

查看:22
本文介绍了当数据可用时,Comboxbox 自动选择第一项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找在数据可用时选择第一项的方法.但是如果源中没有数据,则不要选择.怎么做 ?我对 WPF 很陌生.

I am looking for way to select the first item when data became available. But if no data in the source , then do not select. How to do it ? I am very new to WPF.

<ComboBox Grid.Row="5" Grid.Column="1"
          IsEditable="False"
          ItemsSource="{Binding Source={x:Static l:DirectXResolution.Resolutions}}"
          ToolTip="Resolutions">
    <ComboBox.Resources>
        <l:ResolutionConverter x:Key="resolutionConverter"/>
    </ComboBox.Resources>
    <ComboBox.Text>
        <MultiBinding Converter="{StaticResource resolutionConverter}">
            <Binding Path="GameWidth" Mode="OneWayToSource"/>
            <Binding Path="GameHeight" Mode="OneWayToSource"/>
        </MultiBinding>
    </ComboBox.Text>
</ComboBox>

推荐答案

最简单的方法是使用 SelectedIndex.请检查下面的代码.

The easiest way is to use SelectedIndex. Please, check the code below.

<ComboBox Grid.Row="5" Grid.Column="1"
          IsEditable="False"
          ItemsSource="{Binding Source={x:Static l:DirectXResolution.Resolutions}}"
          ToolTip="Resolutions"
          SelectedIndex="0">
....

这篇关于当数据可用时,Comboxbox 自动选择第一项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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