C# 组合框项未加载到WPF中

C# 组合框项未加载到WPF中,c#,wpf,visual-studio,combobox,wpf-controls,C#,Wpf,Visual Studio,Combobox,Wpf Controls,我的组合框项目未显示。它在visual studio 2015上运行良好。但当我在visual studio 2013中尝试此功能时,它没有显示任何内容。我在ComboBox_加载的函数中设置了调试点,从中我看到编译器跳过了最后3行。如何为Visual Studio 2013解决此问题。提前谢谢 <Window x:Class="GraphicalUserInterface.ShowDataByObjectsWindow" xmlns="http://schemas.microso

我的组合框项目未显示。它在visual studio 2015上运行良好。但当我在visual studio 2013中尝试此功能时,它没有显示任何内容。我在ComboBox_加载的函数中设置了调试点,从中我看到编译器跳过了最后3行。如何为Visual Studio 2013解决此问题。提前谢谢

<Window x:Class="GraphicalUserInterface.ShowDataByObjectsWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="ShowDataByObjectsWindow" Height="300" Width="300">
<Grid Background="#FFE5E5E5">
    <Grid.RowDefinitions>
        <RowDefinition Height="*"/>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>
    <StackPanel Grid.Row="0" Margin="10">
        <TextBlock FontWeight="Bold" Text="Object Options"/>
        <ComboBox  x:Name="dbObjects" Loaded="ComboBox_Loaded" SelectionChanged="ComboBox_SelectionChanged"/>
    </StackPanel>
</Grid>

public分部类ShowDataByObjectsWindow:窗口
{
公共列表dataTableName=新列表();
公共静态字符串组合项;
公共ShowDataByObjectsWindow()
{
初始化组件();
}
已加载私有无效组合框(对象发送方,路由目标)
{
dataTableName.Add(“adasd”);
dataTableName.Add(“adaasdsd”);
var comboBox=发送方作为组合框;
comboBox.ItemsSource=dataTableName;
comboBox.SelectedIndex=0;
}
private void组合框\u SelectionChanged(对象发送者,SelectionChangedEventArgs e)
{
var comboBox=发送方作为组合框;
字符串值=组合框。选择编辑项作为字符串;
this.Title=“所选:”+值;
}
}
试试这个

public ObservableCollection<String> Items { get; set; }

//public 
public MainWindow()
{
    InitializeComponent();

    Items = new ObservableCollection<string>();
    Items.Add("test");

    DataContext = this;
}
publicobservableCollection项{get;set;}
//公开的
公共主窗口()
{
初始化组件();
Items=新的ObservableCollection();
项目。添加(“测试”);
DataContext=this;
}
改变你的看法

<Window x:Class="WpfApplication1.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 HorizontalAlignment="Left" ItemsSource="{Binding Path=Items}" Margin="155,56,0,0" VerticalAlignment="Top" Width="120"/>

    </Grid>
</Window>


这很有效

“我已经看到编译器跳过了最后3行”:尝试清理并强制重建项目。似乎您正在运行WPF应用程序的旧版本。我已再次清理和重建。还是一样。没有更新,您的示例正在运行。但每当我尝试在items中添加数据库表名时,它都会出现一个异常,如System.Data.Entity.dll中出现“System.ArgumentException”类型的异常。其他信息:在配置中找不到指定的存储提供程序或该提供程序无效。“代码示例为,'var eData=new DBEntities(); Items=新的ObservableCollection();项目。添加(“测试”);项目。添加(“adasd”);项目。添加(“adaasdsd”);Items.Add(Convert.ToString(eData.Table1));'
<Window x:Class="WpfApplication1.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 HorizontalAlignment="Left" ItemsSource="{Binding Path=Items}" Margin="155,56,0,0" VerticalAlignment="Top" Width="120"/>

    </Grid>
</Window>