mscorlib.dll中发生了'System.Reflection.TargetInvocationException'类型的第一次机会异常

时间:2013-06-26 07:38:24

标签: c# wpf set listboxitem .net

在我的WPF应用程序中,我为列表框项目编写了一个双击事件。当我双击列表框的现有条目时,该条目已成功提交。

这是代码:

private void listBox1_MouseDoubleClick(object sender, MouseButtonEventArgs e)
    {
        //Submit clicked Entry
        try
        {
            ListBoxItem item = (ListBoxItem)sender;
            Harvest_TimeSheetEntry entryToPost = (Harvest_TimeSheetEntry)item.Content;

            if (!entryToPost.isSynced)
            {
                //Check if something is selected in selectedProjectItem For that item
                if (entryToPost.ProjectNameBinding == "Select Project")
                    MessageBox.Show("Please Select a Project for the Entry");
                else
                    Globals._globalController.harvestManager.postHarvestEntry(entryToPost);
            }
            else
            {
                //Already synced.. Make a noise or something
                MessageBox.Show("Already Synced;TODO Play a Sound Instead");
            }
        }
        catch (Exception)
        { }
     }

但是当我从项目组合框中选择projectname时,它会向我显示异常 - TargetInvocationException。 内部异常是:System.InvalidCastException,System.FormatException。

我认为,问题出在projectNamebinding的setter中。那我该怎么办?

projectNameBinding的代码是:

public class HarvestTimeSheetEntry
{
private int _projectid { get; set; }

public string ProjectNameBinding
    {
        set 
        {

                this._projectid = Int32.Parse(value);

        }
        get
        {
            if (entrySource == source.harvest)
                return Globals._globalController.harvestManager.getProjectEntriesThroughId(this._projectid)._name;
            else if (entrySource == source.googlecalendar)
                return "Select Project";
            else if (entrySource == source.processInfo)
                return "Select Project";
            else
                return "Whaaa?";
        }
}

0 个答案:

没有答案