我正在寻找在数据可用时选择第一项的方法.但如果源中没有数据,则不要选择.怎么做 ?我是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>
Run Code Online (Sandbox Code Playgroud)
Jin*_*ung 22
最简单的方法是使用SelectedIndex.请检查下面的代码.
<ComboBox Grid.Row="5" Grid.Column="1"
IsEditable="False"
ItemsSource="{Binding Source={x:Static l:DirectXResolution.Resolutions}}"
ToolTip="Resolutions"
SelectedIndex="0">
....
Run Code Online (Sandbox Code Playgroud)