我是WPF的初学者,并试图将ComboBox的Items绑定到ObservableCollection
我用过这段代码:
XAML
<Window x:Class="comboBinding2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
DataContext="{Binding RelativeSource={RelativeSource Self}}"
Title="MainWindow" Height="350" Width="525">
<Grid>
<ComboBox x:Name="cmbTest" ItemsSource="{Binding Path=cmbContent}" Width="200" VerticalAlignment="Center" HorizontalAlignment="Center" />
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
C#
public MainWindow()
{
cmbTest.ItemsSource = cmbContent;
cmbContent.Add("test 1");
cmbContent.Add("test 2");
InitializeComponent();
}
public ObservableCollection<string> cmbContent { get; set; }
Run Code Online (Sandbox Code Playgroud)
在我尝试调试之前,我没有在此代码上出现任何错误,它会抛出错误:
TargetInvocationError
PresentationFramework.dll中出现未处理的"System.Reflection.TargetInvocationException"类型异常
谁能告诉我我做错了什么?
我在jQuery中有两个函数,一个需要数据,另一个是通过php和json从数据库加载(这部分工作).我的问题是第一个在数据加载之前启动.我怎么解决这个问题?
这里有一些代码可以理解:
function loadBody(){
//Create an calendar of selectet month with classes to Events
}
function loadEvents(){
//loads Events from DB with php and json and puts them into an array
}
Run Code Online (Sandbox Code Playgroud)
我尝试了以下内容:
function loadCal(){
$.when(loadEvents()).done(loadBody());
}
Run Code Online (Sandbox Code Playgroud)