microsoft-ui-xaml icon indicating copy to clipboard operation
microsoft-ui-xaml copied to clipboard

ComboBox weirdly interacts with other controls defined in XAML

Open Balkoth opened this issue 3 years ago • 1 comments

Describe the bug

If a ComboBox has its ItemSource bound to a collection in a viewmodel and its members DisplayMemberPath, SelectedValuePath and SelectedValue are also used to bind to a specific value, the ComboBox does not load/display the selected value on application start, depending on the XAML around the ComboBox. For example a simple TextBox control in front of the ComboBox breaks this scenario.

Sample: ComboBoxTest.zip

Steps to reproduce the bug

  • Open the provided sample and launch it.

  • You see the following window coming up, with no selected item displayed in the ComboBox despite the viewmodel setting things up correctly: image

  • Now go into PayerPage.xaml and comment the textbox so the code looks like this:

<Page
  x:Class="ComboBoxTest.PayerPage"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  xmlns:local="using:ComboBoxTest"
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
  mc:Ignorable="d">

  <Grid>

    <Grid.RowDefinitions>
      <RowDefinition Height="Auto" />
      <RowDefinition Height="Auto" />
      <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>

    <!--<TextBox
      Grid.Row="0"
      Margin="12"
      Text="{x:Bind ViewModel.SelectedPayer.SelectedText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, FallbackValue=''}" />-->
    <ComboBox
      Grid.Row="1"
      Margin="12"
      DisplayMemberPath="Description"
      ItemsSource="{x:Bind AvailablePayers}"
      SelectedValue="{x:Bind ViewModel.SelectedPayer.SelectedValue, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
      SelectedValuePath="PayerId" />
    <Button
      Grid.Row="2"
      Margin="12"
      Click="Button_Click"
      Content="Test" />

  </Grid>

</Page>
  • Launch the application again and notice that now that only the TextBox was commented out the ComboBox displays correctly: image

Expected behavior

The ComboBox should display correctly in any case when the xaml itself is valid.

Screenshots

No response

NuGet package version

WinUI 3 - Windows App SDK 1.2.2: 1.2.221209.1

Windows version

Windows 10 (21H2): Build 19044

Additional context

No response

Balkoth avatar Jan 24 '23 14:01 Balkoth

Note: If you remove the binding from the TextBlock, things work as expected. So this probably has something to do with binding.

JJBrychell avatar Feb 15 '24 00:02 JJBrychell

This issue still persists.

Balkoth avatar Apr 11 '24 15:04 Balkoth