WinUI ComboBox加载时不能正常显示绑定属性

发布时间 2023-06-20 17:18:00作者: 盛沧海

搞WINUI时发现下述问题:

ComboBox的item1绑定了一个属性,但是程序在加载完成后,页面上并不能正常显示(已经设置了默认选择为ComboBox绑定属性那个item,但是就不正常);

而TextBlock绑定相同的属性,是能正常显示的。

 

具体现象如下,左红色框中为TextBlock,右蓝色框中为ComboBox。

 

其xaml代码如下:

  <StackPanel Orientation="Horizontal">
      <Image
          Width="134"
          Height="112"
          Margin="30,15,0,0"
          HorizontalAlignment="Left"
          VerticalAlignment="Bottom"
          Source="../Images/pic_nav@2x.png"
          Stretch="Uniform" />
      <TextBlock Height="77" Foreground="White" FontSize="45" Text="{Binding CurUserName}"/>
      <ComboBox
          Height="77"
          MinWidth="336"
          VerticalAlignment="Center"
          BorderThickness="0"
          CornerRadius="5"
          FontSize="38"
          Foreground="#333333"
          SelectedIndex="0"
          x:Name="combox"
          Style="{StaticResource DefaultComboBoxStyle3}" SelectionChanged="CB_SelectionChanged" >
          <ComboBoxItem Content="{Binding CurUserName}" IsSelected="True"  Style="{StaticResource ComboBoxItemRevealStyle3}" />
          <ComboBoxItem Content="修改密码"  Style="{StaticResource ComboBoxItemRevealStyle3}" />
          <ComboBoxItem Content="退出登录" Style="{StaticResource ComboBoxItemRevealStyle3}" />
      </ComboBox>
  </StackPanel>

目前尚未解决,记之以备忘。