加载UserControl

时间:2017-01-12 20:25:32

标签: wpf entity-framework linq-to-sql user-controls

我在WPF应用程序中创建了一个新视图 当我尝试加载View时,收到以下错误:

"未处理的类型' System.FormatException'发生在mscorlib.dll" "附加信息:输入字符串的格式不正确" "将字符串转换为DateTime时,解析字符串以在将每个变量放入DateTime对象之前获取日期。"

我知道它与我的ViewModel中的LINQ to SQL查询有关,因为当我发表评论时,一切正常;但是,我的模型中没有DateTime字段。

如下所示,模型由字符串,int和bool值组成。

非常感谢对此的任何见解。谢谢你的时间。

模型

 {
    public int ID { get; set; }
    public Nullable<int> employeeNumber { get; set; }
    public string userName { get; set; }
    public string parentBranch { get; set; }
    public string branch { get; set; }
    public bool ATS { get; set; }
    public bool website { get; set; }
    public bool admin { get; set; }
    public bool HR { get; set; }
    public string timesheet { get; set; }
    public string debug { get; set; }
}

查看

<UserControl x:Class="Craig_Tools.ApplicationTrackingSystem.Views.Security"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
         xmlns:dg="clr-namespace:Craig_Tools.ApplicationTrackingSystem.userControls.datagrids"
         mc:Ignorable="d" 
         d:DesignHeight="300" d:DesignWidth="300">
<DockPanel>
    <ContentControl DockPanel.Dock="Top" HorizontalAlignment="Stretch" VerticalAlignment="Top">
        <dg:dg_security />
    </ContentControl>
</DockPanel>

视图模型

public partial class SecurityViewModel : ViewModelBase
{
    public SecurityViewModel()
    {
        LoadSecurity();
    }

     public void LoadSecurity()
    {
        using (JobSeekersEntities db = new JobSeekersEntities())
        {
            var q = (from s in db.securities
                     select s).ToList();

            securityList = new ObservableCollection<security>(q);
        }
    }

    //ObservableCollections
    private ObservableCollection<security> securityList;
    public ObservableCollection<security> SecurityList
    {
        get { return securityList; }
        set
        {
            securityList = value;
            RaisePropertyChangedEvent("SecurityList");
        }
    }
    //Constructors
    private int selectedSecurity;
    public int SelectedSecurity
    {
        get { return selectedSecurity; }
        set
        {
            { selectedSecurity = value; }
            RaisePropertyChangedEvent("SelectedSecurity");
        }
    }
    //Commands

}

0 个答案:

没有答案