TwoWay绑定ComboBox到

TwoWay绑定ComboBox到

本文介绍了TwoWay绑定ComboBox到.NET 4.5中的静态属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好,我刚刚发布了问题,但我想我没有做错什么。我的代码(和所有答案的代码)是正确的,但我的dev-maschine运行与.NET4.5显然有一个问题绑定的组合框...

Well, i just posted this question, but i figured that i am not doing anything wrong. My code (and the code of all of the answers) is correct, but my dev-maschine runs with .NET4.5 which apparently has a problem with the binding of the combobox...

这里是一个新版本的问题:如何双向绑定组合框的SelectedItem到.NET4.5中的静态属性?

So here a new version of the question: How to two-way bind a combobox's SelectedItem to a static Property in .NET4.5?

以下代码片段在.net4中可用,但在.NET4.5中不可用。在4.5,只是选择的值不传播回我的静态属性。

The following code snippets work in .net4 but not in .NET4.5. In 4.5 it is just that the selected value is not propagated back into my static property.

我的ViewModel:

My ViewModel:

public class MainWindowViewModel
{
    public static List<String> MyElements { get; set; }
    public static string SelectedElement { get; set; }

    static MainWindowViewModel()
    {
        MyElements = new List<string>() {"a", "b", "c"};
        SelectedElement = "a";
    }
}

和我的XAML

<Window.Resources>
    <me:MainWindowViewModel x:Key="model"/>
</Window.Resources>

<StackPanel>
    <ComboBox
        ItemsSource="{Binding Source={x:Static me:MainWindowViewModel.MyElements}, Mode=OneWay}"
        SelectedItem="{Binding Source={StaticResource model}, Path=SelectedElement}" />
</StackPanel>

有人知道如何实现ComboBox的SelectedItem到静态属性的双向绑定在.NET4.5中?

Does anybody have an idea how to achieve this two-way binding of a ComboBox's SelectedItem to a static Property in .NET4.5?

推荐答案

请参阅。每个选择器控制被这个问题感染。

Please refer to my report on Microsoft Connect. Every Selector control is infected by this issue.

最后,几个星期前Microsoft发布了一个适当的补丁,已通过Windows Update分发。 (WPF - 第7期)

Finally, a few weeks ago Microsoft released an appropriate patch which has already been distributed through Windows Update. see Knowledge Base KB2805222 (WPF - Issue 7)

这篇关于TwoWay绑定ComboBox到.NET 4.5中的静态属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 10:45