且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

WPF绑定,OneWayToSource,"物业获取方法未找到与QUOT。

更新时间:2022-12-08 19:41:31

我想出来的东西及以下作品code。我希望这有助于:

I tried something out and the code below works. I hope this helps:

code-背后:


public partial class MainWindow : Window
    {
        private SomeCustomType registry;
        public SomeCustomType Registry { set { registry = value; } }

        public MainWindow()
        {
            InitializeComponent();
            this.comboBox.DataContext = this;
        }

    }

    public class SomeType
    {
        public static SomeCustomType Property1 { get { return new SomeCustomType() { Name = "Item1" }; } }
        public static SomeCustomType Property2 { get { return new SomeCustomType() { Name = "Item2" }; } }
    }

    public class SomeCustomType
    {
        public string Name { get; set; }
    }

XAML:

<ComboBox x:Name="comboBox" SelectedValue="{Binding Registry, Mode=OneWayToSource, UpdateSourceTrigger=PropertyChanged}" 
              SelectedValuePath="Tag" SelectedIndex="0">
    <ComboBoxItem Content="Item1" Tag="{x:Static local:SomeType.Property1}" />
    <ComboBoxItem Content="Item2" Tag="{x:Static local:SomeType.Property2}" />
</ComboBox>