English 中文(简体)
我如何将可观测的孔波-Box连接起来?
原标题:How do I bind an ObservableCollection to a ComboBox?

我如何在<条码>ComboBox和<条码>之间工作具有基本约束力。 ObservableCollection? 我只能拿错误的信息。

VB:

Class MainWindow
    Dim Units As New ObservableCollection(Of String)

    Private Sub Window_Loaded(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
        Units.Clear()
        Units.Add("in")
        Units.Add("mm")
        Units.Add("cm")
    End Sub
End Class

XAML:

<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
    <ComboBox Height="59" HorizontalAlignment="Left" Margin="136,96,0,0" Name="ComboBox1" VerticalAlignment="Top" Width="319"
              ItemsSource="{Binding Units}"/>
</Grid>

不管我做什么,<条码>ComboBox似乎总是空洞的,在座标上有一个错误的信息:

系统。 视窗。 数据 错误:40 不动产单位,未在标的Maindow(Name= )上找到。 约束性表达: Path=Units; DataItem= MainWindow(Name= );具体目标要素是ComboBox(Name=ComboBox1);目标财产是项目来源(类型IE

最佳回答

在XAML中,改名为{具有约束力的},或等同,{具有约束力的路径=}:

<ComboBox Height="59" HorizontalAlignment="Left" Margin="136,96,0,0" Name="ComboBox1" VerticalAlignment="Top" Width="319" ItemsSource="{Binding}"/>

根据背书的代码,将数据背景明确表述给标人。

ComboBox1.DataContext = Units;
问题回答

暂无回答




相关问题
WPF Datagrid, Setting the background of combox popup

I would like to change the color of the popup background when using a DatagridComboboxColumn in the WPF Toolkit datagrid. I ve edited the Template for a normal Combobox and it works great for selected ...

How to insert ComboBox item into ListBox? [winforms]

The question is very simple, How to insert ComboBox selected item into ListBox using c#? I have tried with this: listbox.Items.Add(combobox.SelectedItem); and some other permutations but it always ...

How do I bind a ComboBox to a one column list

I ve seen how to bind a ComboBox to a list that has columns like this: ItemsSource="{Binding Path=Entries}" DisplayMemberPath="Name" SelectedValuePath="Name" SelectedValue="{Binding Path=Entry}" But ...

Wpf Combobox Limit to List

We are using Wpf Combobox to allow the user to do the following things: 1) select items by typing in the first few characters 2) auto complete the entry by filtering the list 3) suggesting the first ...

热门标签