【问题标题】:WPF XAML combobox synchronized with the actual value upon updated ItemsSourceWPF XAML 组合框在更新 ItemsSource 时与实际值同步
【发布时间】:2018-11-27 09:18:44
【问题描述】:

我在保持组合框与实际选定值同步时遇到问题。我有一个数据网格,我将选定的行值绑定到一个对象。所选对象具有值为“test2”的属性代码。

我的组合框有一个选项“test1”和“test2”和“test3”

当我选择此对象时,组合框会更新为正确的值“test2”,但在更新 ItemsSource 时,由于我使用 isSynchronizedWithCurrentItem = true,它会自动设置组合框中的第一个替代项。我的应用程序每 10 秒轮询一次新项目并更新/刷新 itemssource,我的问题是如何使组合框与实际选择的组合框替代项/项目同步?

如果我选择“test3”并且 itemssource 更新,组合框仍将显示“test3”而不是“test1”作为第一个默认值。或者更确切地说,如果我没有选择另一个值,它仍然会与所选对象“test”中的当前值保持不变?

这是我的 XAML 代码:我要绑定的对象是公共 UserObject 对象。

<TextBlock Grid.Column="1" Grid.Row="0" Text="Name:" VerticalAlignment="Center"  />
<telerik:RadComboBox Grid.Column="2" Grid.Row="0" Text="{Binding Object.Code, Mode=TwoWay}" Margin="4 4 0 4" FontSize="13" IsReadOnly="True" ItemsSource="{Binding Objects}" 
     DisplayMemberPath="Code" SelectedValue = "{Binding Object.Code}"  SelectedValuePath="Code" 
     SelectedItem="{Binding SelectedCode}" IsSynchronizedWithCurrentItem="True"  />

我该如何解决这个问题?

【问题讨论】:

    标签: c# wpf xaml telerik


    【解决方案1】:

    你可以试试这个:

    private void RefreshFunc()
        {
            string objectCode = Object.Code;
    
            //update/refresh the itemssource
            ToRefreshItemsSource();
    
            Object.Code = objectCode;
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-02
      • 2013-11-03
      相关资源
      最近更新 更多