GetBindingExpression returns null the second time it is called

I found strange behavior GetBindingExpression()when a function is called in the ComboBox SelectedValue property.

It works fine the first time it is called, but after calling UpdateTarget () in the returned BindingExpression, that BindingExpression seems to be removed from the property. Next time, GetBindingExpression () from the property returns null.

BindingExpression exp;

// call it first time, returns an expression, and UpdateTarget success.
exp = ((ComboBox)obj).GetBindingExpression(ComboBox.SelectedValueProperty);

// call UpdateTarget
if (exp != null) exp.UpdateTarget();

// call it the second time, and now it returns null!
exp = ((ComboBox)obj).GetBindingExpression(ComboBox.SelectedValueProperty);

if (exp != null) exp.UpdateTarget();

If I remove the call to UpdateTarget (), the next GetBindingingExpression()one still returns a valid BindingExpression.

This issue does not occur in the CheckBox IsChecked property. It always works great with the IsChecked CheckBox property.

XAML is as follows:

  <Style TargetType="{x:Type ComboBox}" x:Key="GainComboBoxStyle_0x00000022">
     <Setter Property="Height" Value="20" />
     <Setter Property="MaxWidth" Value="80" />
     <Setter Property="FontFamily" Value="Calibri"/>
     <Setter Property="FontSize" Value="15"/>
     <Setter Property="FontWeight" Value="UltraBold"/>
     <Setter Property="Tag" Value="{StaticResource moduleGain_0x00000022}" />
     <Setter Property="Visibility" Value="{Binding Mode=OneWay, Converter={StaticResource getVisibilityOfGainConverter}}"/>

     <Style.Triggers>
        <DataTrigger Binding="{Binding Mode=OneWay, Converter={StaticResource isShowingGain}}" Value="True">
           <Setter Property="SelectedValue" Value="{Binding Path=., RelativeSource={RelativeSource Mode=Self}, Mode=OneWay, Converter={StaticResource getGainValue}}"/>
           <Setter Property="DisplayMemberPath" Value="Name" />
           <Setter Property="SelectedValuePath" Value="Name" />
           <Setter Property="IsSynchronizedWithCurrentItem" Value="False" />
           <Setter Property="ItemsSource" Value="{Binding Path=GainQ13Indices, Mode=OneTime}" />
        </DataTrigger>
     </Style.Triggers>
  </Style>

  <Style TargetType="{x:Type CheckBox}" x:Key="EnableCheckBoxStyle_0x00000010">
     <Setter Property="MaxWidth" Value="16"/>
     <Setter Property="Tag" Value="{StaticResource
                      moduleEnable_0x00000010}" />
     <Setter Property="Visibility" Value="{Binding Mode=OneWay, Converter={StaticResource getVisibilityOfEnableConverter}}"/>
     <Style.Triggers>
        <DataTrigger Binding="{Binding Mode=OneWay, Converter={StaticResource isShowingEnable}}" Value="True">
           <Setter Property="IsChecked" Value="{Binding Path=., RelativeSource={RelativeSource
                                          Mode=Self}, Mode=OneWay,
                                          Converter={StaticResource
                                          moduleEnableDisableConverter} }" />
        </DataTrigger>
     </Style.Triggers>
  </Style>

UpdateTarget() BindingExpression SelectedValue ComboBox? IsChecked CheckBox?

+3
1

, SelectedValue , GainQ13Indices, - , , . , SelectedValue , , ItemsSource.

, IsChecked, , , , ComboBox, ( ).

, - ​​.

( ):

public ObservableCollection<Gain> GainQ13Indices { get; private set; }

public Gain SelectedGainQ13Indice { get; set; }
+1

All Articles