How to set default value in code first Entity Framework - c#

I am setting up default value for CreatedDate in my entity class as shown below. But during implementation I get the value 01/01/0001
private DateTime _createdDate = DateTime.Now;
private DateTime _modifiedDate = DateTime.Now;
public DateTime CreatedDate
{
get { return _createdDate; }
set { _createdDate = value; }
}
public string LastModifiedBy { get; set; }
public DateTime LastModifiedDate
{
get { return _modifiedDate; }
set { _modifiedDate = value; }
}
here is my implementation
public bool AddJewelryItem(List<Entities.Jewelry> jewelryList)
{
bool isSuccess = false;
try
{
using (var db = new Context())
{
foreach (Entities.Jewelry jewelry in jewelryList)
{
db.JewelryItemsList.Add(jewelry.jewelryItems);
db.SaveChanges();
jewelry.jewelryAddnlDetails.JewelryID = jewelry.jewelryItems.JewelryID;
if (jewelry.jewelryAddnlDetails.JewelryID != 0)
{
db.JewelryAddnlDetailsList.Add(jewelry.jewelryAddnlDetails);
db.SaveChanges();
}
}
isSuccess = true;
}
}

Related

Return the max Date

[Column, Nullable] public DateTime? ModifiedDate { get; set; }
[Association(QueryExpressionMethod = nameof(GetfffModified), CanBeNull = true)]
public DateTime? xxxModified { get; set; }
public static Expression<Func<Offer, IDataContext, IQueryable<DateTime?>>> GetfffModified()
{
return (obj, db) => db.GetTable<OfferProducts>()
.Where(rel => rel.OfferId == obj.OfferId)
.OrderByDescending(i => i.ModifiedDate)
.Select(x => x.ModifiedDate)
.Take(1);
}
// here I am trying to set max date between ModifiedDate and xxxModified
public DateTime? Modified { get { return ModifiedDate; } set { ModifiedDate = value; } }
In above method I am trying to set the max date between ModifiedDate and xxxModified for Modified values .
Is there any possible to do like that ?
private DateTime? _FinalDate;
public DateTime? FinalDate
{
get
{
if (ModifiedDate < OfferProductsModified)
{
return OfferProductsModified;
}
else
{
return ModifiedDate;
}
}
set
{
if (ModifiedDate < OfferProductsModified)
{
_FinalDate = value;
}
else
{
//DEFAULT Value.
_FinalDate = ModifiedDate;
}
}
}
I found a way

C# OrderBy on nested object Property

I'm using reflection to order by list of objects.
I would like to order this list on a property of a nested object.
This is the code in which I get the list, and I do the sorting of the list
List<DocumentModel> documentList;
if (contractid == -1)
documentList = helpsi.framework.core.CustomerProvider.DocumentModel.getAllDocumentModelListByCustomer(custid, custtypeid);
else
documentList = helpsi.framework.core.CustomerProvider.DocumentModel.getAllDocumentModelListGridByContract(contractid);
if (sord.Equals("asc")) documentList = documentList.OrderBy(x => x.GetType().GetProperty(sidx.ToUpper()).GetValue(x, null)).ToList();
else documentList = documentList.OrderByDescending(x => x.GetType().GetProperty(sidx.ToUpper()).GetValue(x, null)).ToList();
The DocumentModel object has a DocumentModelType property that contains a DocumentStateDesc string property.
Can I sort the list by the DocumentTypeDesc property using reflection? What can I use in the sidx parameter?
Thanks
This is the DocumentModel class
public class DocumentModel : ObjBase
{
#region Attributi
private long _id;
private string _documentModel;
private long? _documentModelTypeId;
private long? _documentModelIssuingEntityId;
private string _documentModelFilename;
private string _documentModelPath;
private DateTime? _documentModelStart;
private DateTime? _documentModelEnd;
private string _documentModelVersion;
private long _contractId;
private string _contractNumber;
private long _contractTypeId;
private long _contractStateId;
private string _contractState;
private long _documentModelStateId;
private string _documentModelValoId;
private DateTime? _documentModelUploadDate;
private byte[] _documentModelContent;
private long _documentModelFilter;
private bool _flagDeleted;
private long _userId;
private int _orderDocumentModel = 0;
private string _placeOfIssue;
private string _issuingEntity;
private DateTime? _releaseDate;
private int? _idOpInsert;
private int? _idOpId;
private long? _customerId;
private long? _customerTypeId;
private string _customerNumber;
private DateTime? _documentModelInvalidated;
private bool _flagValidating;
private string _fileRemotePath;
private long? _folderId;
private string _folderName;
protected new HELPSI_Database HELPSI_Database = Common.HELPSI_Database.HELPSI_Anag;
[XmlElement(ElementName = "CODE_DOCUMENT_MODEL_ID")]
public long CODE_DOCUMENT_MODEL_ID
{
get { return _id; }
set { _id = value; }
}
[XmlElement(ElementName = "DESC_DOCUMENT_MODEL")]
public string DESC_DOCUMENT_MODEL
{
get { return _documentModel; }
set { _documentModel = value; }
}
[XmlElement(ElementName = "CODE_DOCUMENT_MODEL_TYPE_ID")]
public long? CODE_DOCUMENT_MODEL_TYPE_ID
{
get { return _documentModelTypeId; }
set { _documentModelTypeId = value; }
}
[XmlElement(ElementName = "CODE_DOCUMENT_MODEL_ISSUING_ENTITY_ID")]
public long? CODE_DOCUMENT_MODEL_ISSUING_ENTITY_ID
{
get { return _documentModelIssuingEntityId; }
set { _documentModelIssuingEntityId = value; }
}
[XmlElement(ElementName = "DESC_DOCUMENT_MODEL_FILENAME", IsNullable = true)]
public string DESC_DOCUMENT_MODEL_FILENAME
{
get { return _documentModelFilename; }
set { _documentModelFilename = value; }
}
[XmlElement(ElementName = "DESC_DOCUMENT_MODEL_PATH", IsNullable=true)]
public string DESC_DOCUMENT_MODEL_PATH
{
get { return _documentModelPath; }
set { _documentModelPath = value; }
}
[XmlElement(ElementName = "DATE_DOCUMENT_MODEL_START")]
public DateTime? DATE_DOCUMENT_MODEL_START
{
get { return _documentModelStart; }
set { _documentModelStart = value; }
}
[XmlElement(ElementName = "DATE_DOCUMENT_MODEL_END")]
public DateTime? DATE_DOCUMENT_MODEL_END
{
get { return _documentModelEnd; }
set { _documentModelEnd = value; }
}
[XmlElement(ElementName = "DESC_DOCUMENT_MODEL_VERSION", IsNullable = true)]
public string DESC_DOCUMENT_MODEL_VERSION
{
get { return _documentModelVersion; }
set { _documentModelVersion = value; }
}
[XmlElement(ElementName = "CODE_CONTRACT_ID")]
public long CODE_CONTRACT_ID
{
get { return _contractId; }
set { _contractId = value; }
}
[XmlElement(ElementName = "FLAG_DELETED")]
public bool FLAG_DELETED
{
get { return _flagDeleted; }
set { _flagDeleted = value; }
}
[XmlElement(ElementName = "CODE_USER_ID")]
public long CODE_USER_ID
{
get { return _userId; }
set { _userId = value; }
}
[XmlElement(ElementName = "ORDER_DOCUMENT_MODEL")]
public int ORDER_DOCUMENT_MODEL
{
get { return _orderDocumentModel; }
set { _orderDocumentModel = value;}
}
private DocumentModelType _documentModelType;
[XmlElement(ElementName = "DocumentModelType", IsNullable = true)]
public DocumentModelType documentModelType
{
get { return _documentModelType; }
set { _documentModelType = value; }
}
private DocumentModelState _documentModelState;
[XmlElement(ElementName = "DocumentModelState", IsNullable = true)]
public DocumentModelState documentModelState
{
get { return _documentModelState; }
set { _documentModelState = value; }
}
private DocumentModelIssuingEntity _documentModelIssuingEntity;
[XmlElement(ElementName = "DocumentModelIssuingEntity", IsNullable = true)]
public DocumentModelIssuingEntity documentModelIssuingEntity
{
get { return _documentModelIssuingEntity; }
set { _documentModelIssuingEntity = value; }
}
//private DocumentModelFolder _documentModelFolder;
//[XmlElement(ElementName = "DocumentModelFolder", IsNullable = true)]
//public DocumentModelFolder documentModelFolder
//{
// get { return _documentModelFolder; }
// set { _documentModelFolder = value; }
//}
[XmlElement(ElementName = "CODE_DOCUMENT_MODEL_STATE_ID")]
public long CODE_DOCUMENT_MODEL_STATE_ID
{
get { return _documentModelStateId; }
set { _documentModelStateId = value; }
}
[XmlElement(ElementName = "VALO_DOCUMENT_MODEL_ID")]
public string VALO_DOCUMENT_MODEL_ID
{
get { return _documentModelValoId; }
set { _documentModelValoId = value; }
}
[XmlElement(ElementName = "DATE_DOCUMENT_MODEL_UPLOAD")]
public DateTime? DATE_DOCUMENT_MODEL_UPLOAD
{
get { return _documentModelUploadDate; }
set { _documentModelUploadDate = value; }
}
[XmlElement(ElementName = "DESC_DOCUMENT_MODEL_CONTENT")]
public byte[] DESC_DOCUMENT_MODEL_CONTENT
{
get { return _documentModelContent; }
set { _documentModelContent = value; }
}
[XmlElement(ElementName = "CODE_DOCUMENT_MODEL_FILTER_ID")]
public long CODE_DOCUMENT_MODEL_FILTER_ID
{
get { return _documentModelFilter; }
set { _documentModelFilter = value; }
}
private long _code_siteId;
[XmlElement(ElementName = "CODE_SITEID")]
public long CODE_SITEID
{
get { return _code_siteId; }
set { _code_siteId = value; }
}
[XmlElement(ElementName = "DESC_DOCUMENT_RELEASE_PLACE")]
public string DESC_DOCUMENT_RELEASE_PLACE
{
get { return _placeOfIssue; }
set { _placeOfIssue = value; }
}
[XmlElement(ElementName = "DESC_DOCUMENT_RELEASED_BY")]
public string DESC_DOCUMENT_RELEASED_BY
{
get { return _issuingEntity; }
set { _issuingEntity = value; }
}
[XmlElement(ElementName = "DATE_DOCUMENT_RELEASED")]
public DateTime? DATE_DOCUMENT_RELEASED
{
get { return _releaseDate; }
set { _releaseDate = value; }
}
[XmlElement(ElementName = "CODE_OP_INSERT_ID")]
public int? CODE_OP_INSERT_ID
{
get { return _idOpInsert; }
set { _idOpInsert = value; }
}
[XmlElement(ElementName = "CODE_OP_ID_ID")]
public int? CODE_OP_ID_ID
{
get { return _idOpId; }
set { _idOpId = value; }
}
[XmlElement(ElementName = "CODE_CUSTOMERID")]
public long? CODE_CUSTOMERID
{
get { return _customerId; }
set { _customerId = value; }
}
[XmlElement(ElementName = "CODE_CUSTOMERTYPEID")]
public long? CODE_CUSTOMERTYPEID
{
get { return _customerTypeId; }
set { _customerTypeId = value; }
}
[XmlElement(ElementName = "DATE_DOCUMENT_MODEL_INVALIDATED")]
public DateTime? DATE_DOCUMENT_MODEL_INVALIDATED
{
get { return _documentModelInvalidated; }
set { _documentModelInvalidated = value; }
}
[XmlElement(ElementName = "FLAG_VALIDATING")]
public bool FLAG_VALIDATING
{
get { return _flagValidating; }
set { _flagValidating = value; }
}
[XmlElement(ElementName = "CODE_CONTRACT_STATES_ID")]
public long CODE_CONTRACT_STATES_ID
{
get { return _contractStateId; }
set { _contractStateId = value; }
}
[XmlElement(ElementName = "DESC_CONTRACT_STATES")]
public string DESC_CONTRACT_STATES
{
get { return _contractState; }
set { _contractState = value; }
}
[XmlElement(ElementName = "CODE_CONTRACT_TYPE_ID")]
public long CODE_CONTRACT_TYPE_ID
{
get { return _contractTypeId; }
set { _contractTypeId = value; }
}
[XmlElement(ElementName = "DESC_CONTRACT_NUMBER")]
public string DESC_CONTRACT_NUMBER
{
get { return _contractNumber; }
set { _contractNumber = value; }
}
[XmlElement(ElementName = "DESC_CONTACT_NUMBER")]
public string DESC_CONTACT_NUMBER
{
get { return _customerNumber; }
set { _customerNumber = value; }
}
[XmlElement(ElementName = "CODE_DOCUMENT_MODEL_FOLDER_ID")]
public long? CODE_DOCUMENT_MODEL_FOLDER_ID
{
get { return _folderId; }
set { _folderId = value; }
}
[XmlElement(ElementName = "DocumentModelFolderName")]
public string DocumentModelFolderName
{
get { return _folderName; }
set { _folderName = value; }
}
[XmlElement(ElementName = "DESC_FILEREMOTEPATH")]
public string DESC_FILEREMOTEPATH
{
get { return _fileRemotePath; }
set { _fileRemotePath = value; }
}
#endregion
}
And this is the DocumentModelType Class
public class DocumentModelType : ObjBase
{
#region Attributi
private long _id;
private string _documentModelType;
private bool _flagDeleted;
private long _userId;
protected new HELPSI_Database HELPSI_Database = Common.HELPSI_Database.HELPSI_Anag;
[XmlElement(ElementName = "CODE_DOCUMENT_MODEL_TYPE_ID")]
public long CODE_DOCUMENT_MODEL_TYPE_ID
{
get { return _id; }
set { _id = value; }
}
[XmlElement(ElementName = "DESC_DOCUMENT_MODEL_TYPE")]
public string DESC_DOCUMENT_MODEL_TYPE
{
get { return _documentModelType; }
set { _documentModelType = value; }
}
[XmlElement(ElementName = "FLAG_DELETED")]
public bool FLAG_DELETED
{
get { return _flagDeleted; }
set { _flagDeleted = value; }
}
[XmlElement(ElementName = "CODE_USER_ID")]
public long CODE_USER_ID
{
get { return _userId; }
set { _userId = value; }
}
#endregion
}
You should be using x => x.DocumentModelType.GetType().GetProperty(sidx.ToUpper()).GetValue(x.DocumentModelType, null) inside OrderBy clause. Here sidx should be DocumentStateDesc as you mentioned that you want order on this column.
Complete code will be like below.
List<DocumentModel> documentList;
if (contractid == -1)
documentList = helpsi.framework.core.CustomerProvider.DocumentModel.getAllDocumentModelListByCustomer(custid, custtypeid);
else
documentList = helpsi.framework.core.CustomerProvider.DocumentModel.getAllDocumentModelListGridByContract(contractid);
if (sord.Equals("asc"))
documentList = documentList.OrderBy(x => x.DocumentModelType.GetType().GetProperty(sidx.ToUpper()).GetValue(x.DocumentModelType, null)).ToList();
else
documentList = documentList.OrderByDescending(x => x.DocumentModelType.GetType().GetProperty(sidx.ToUpper()).GetValue(x.DocumentModelType, null)).ToList();
One quick and dirty fix is to introduce property in parent class that just returns the property value of another property. Just don't assign XmlElement attribute to it. If the classes are auto-generated you can't change them, but they are probably declared as partial, and then you can add this new property in additional class definition.
public string DocumentModelType_DocumentStateDesc { get => DocumentModelType.DocumentStateDesc; }
But if you want to have a general solution for several properties with several sub-properties then some sort of pathing is required. You could String.Split sidx on some delimiter like '\' or '.', use recursion, and then OrderBy the last item in the path.

ListView Item does not appear to cast correctly

I have in Xamarin.Forms XAML ListView that is being sourced by a typed ItemSource:
ObservableCollection<WorkOrderActivity> serviceList =
new ObservableCollection<WorkOrderActivity>();
servicelistview.ItemsSource = serviceList;
Here is my table:
public class WorkOrderActivity
{
string id;
int workordernumber;
string activity;
string service;
string activitylocation;
float actualquantity;
string reference;
DateTime arrivaltime;
DateTime departuretime;
string remarks;
bool complete;
bool done;
string uom;
int startgauge;
int endgauge;
int contactgauge;
[JsonProperty(PropertyName = "id")]
public string Id
{
get { return id; }
set { id = value; }
}
[JsonProperty(PropertyName = "workordernumber")]
public int WorkOrderNumber
{
get { return workordernumber; }
set { workordernumber = value; }
}
[JsonProperty(PropertyName = "activity")]
public string Activity
{
get { return activity; }
set { activity = value; }
}
[JsonProperty(PropertyName = "service")]
public string Service
{
get { return service; }
set { service = value; }
}
[JsonProperty(PropertyName = "arrivaltime" )]
public DateTime ArrivalTime
{
get { return arrivaltime; }
set { arrivaltime = value; }
}
[JsonProperty(PropertyName = "departuretime")]
public DateTime DepartureTime
{
get { return departuretime; }
set { departuretime = value; }
}
[JsonProperty(PropertyName = "activitylocation")]
public string ActivityLocation
{
get { return activitylocation; }
set { activitylocation = value; }
}
[JsonProperty(PropertyName = "actualquantity")]
public float ActualQuantity
{
get { return actualquantity; }
set { actualquantity = value; }
}
[JsonProperty(PropertyName = "startgauge")]
public int StartGauge
{
get { return startgauge; }
set { startgauge = value; }
}
[JsonProperty(PropertyName = "endgauge")]
public int EndGauge
{
get { return endgauge; }
set { endgauge = value; }
}
[JsonProperty(PropertyName = "contactgauge")]
public int ContactGauge
{
get { return contactgauge; }
set { contactgauge = value; }
}
[JsonProperty(PropertyName = "reference")]
public string Reference
{
get { return reference; }
set { reference = value; }
}
[JsonProperty(PropertyName = "remarks")]
public string Remarks
{
get { return remarks; }
set { remarks = value; }
}
[JsonProperty(PropertyName = "uom")]
public string UOM
{
get { return uom; }
set { uom = value; }
}
[JsonProperty(PropertyName = "done")]
public bool Done
{
get { return done; }
set { done = value; }
}
[JsonProperty(PropertyName = "complete")]
public bool Complete
{
get { return complete; }
set { complete = value; }
}
[Version]
public string Version { get; set; }
[CreatedAt]
public DateTimeOffset CreatedAt { get; set; }
[UpdatedAt]
public DateTimeOffset UpdatedAt { get; set; }
[Deleted]
public bool Deleted { get; set; }
}
The problem occurs when I select an item from the listview, I get the correct record, but the datetime fields only have date in them, the time is zero.
private void servicelistview_ItemTapped(object sender, ItemTappedEventArgs e)
{
var p = (WorkOrderActivity)e.Item;
When I display the record in the listview it comes up with the correct time and date, it just appears that when I cast the selected item as a WorkOrderActivity.
Any ideas?
DateTime.Date returns 00:00:00; from the DateTime.Date documentation:
// Returns:
// A new object with the same date as this instance, and the time value set to 12:00:00
// midnight (00:00:00).
Example:
var dt = new DateTime(2018, 01, 14, 1, 2, 3);
Debug.WriteLine(dt.Date);
Debug.WriteLine(dt.Hour + " " + dt.Minute + " " + dt.Second);
Output:
1/14/2018 12:00:00 AM
1 2 3

Deserialization the json string gives Value cannot be null. Parameter name: s

"[{\"active\":true,\"campaignId\":11401,\"createdtime\":1355919181000,\"description\":\"Ankit Demo Edited By Nirav\",\"enddate\":1363132800000,\"groupId\":10179,\"isdeleted\":false,\"lastmodifiedby\":10405,\"modifiedtime\":1362556187000,\"name\":\"Ankit Demo\",\"noofweek\":12,\"organizationId\":11153,\"startdate\":1355875200000,\"status\":2,\"userId\":11161},
{\"active\":true,\"campaignId\":21901,\"createdtime\":1358493958000,\"description\":\"sdadadasd\",\"enddate\":1359072000000,\"groupId\":10179,\"isdeleted\":false,\"lastmodifiedby\":10405,\"modifiedtime\":1358751277000,\"name\":\"NEW CAMP TEST\",\"noofweek\":1,\"organizationId\":10707,\"startdate\":1358467200000,\"status\":4,\"userId\":10405},
{\"active\":true,\"campaignId\":33601,\"createdtime\":1361441582000,\"description\":\"dasdsadasd\",\"enddate\":1363219200000,\"groupId\":10179,\"isdeleted\":false,\"lastmodifiedby\":10405,\"modifiedtime\":1361795632000,\"name\":\"BHAVIK UTC\",\"noofweek\":3,\"organizationId\":10707,\"startdate\":1361404800000,\"status\":2,\"userId\":10405}]"
I have Above Jsong String in my string variable ..and i want to convert this json string into an object of my custom class..i have created the custom class ..
following is the code in which i getingg the response in json from HttpWebResponse and converting in list object of my custom class
HttpWebResponse response = default(HttpWebResponse);
try
{
response = (HttpWebResponse)request.GetResponse();
// response.Close()
string sResult = null;
using (StreamReader responseReader = new StreamReader(response.GetResponseStream()))
{
sResult = responseReader.ReadToEnd();
}
response.Close();
Console.WriteLine(sResult);
List<Class1> myDeserializedObjList = (List<Class1>)Newtonsoft.Json.JsonConvert.DeserializeObject(Request[sResult], typeof(List<Class1>));
int counts= myDeserializedObjList.Count;
}
but its giving me error
Value cannot be null.
Parameter name: s
Can anyone Please guide me how to solve this problem?
this is my custom class to which i want to assign the objects from json string
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
/// <summary>
/// Summary description for Class1
/// </summary>
public class Class1
{
private Boolean active;
public Boolean Active
{
get { return active; }
set { active = value; }
}
private long campaignId;
public long CampaignId
{
get { return campaignId; }
set { campaignId = value; }
}
private long createdtime;
public long Createdtime
{
get { return createdtime; }
set { createdtime = value; }
}
private string description;
public string Description
{
get { return description; }
set { description = value; }
}
private long enddate;
public long Enddate
{
get { return enddate; }
set { enddate = value; }
}
private long groupId;
public long GroupId
{
get { return groupId; }
set { groupId = value; }
}
private Boolean isdeleted;
public Boolean Isdeleted
{
get { return isdeleted; }
set { isdeleted = value; }
}
private long modifiedtime;
public long Modifiedtime
{
get { return modifiedtime; }
set { modifiedtime = value; }
}
private long lastmodifiedby;
public long Lastmodifiedby
{
get { return lastmodifiedby; }
set { lastmodifiedby = value; }
}
private string name;
public string Name
{
get { return name; }
set { name = value; }
}
private int noofweek;
public int Noofweek
{
get { return noofweek; }
set { noofweek = value; }
}
private long organizationId;
public long OrganizationId
{
get { return organizationId; }
set { organizationId = value; }
}
private long startdate;
public long Startdate
{
get { return startdate; }
set { startdate = value; }
}
private Boolean status;
public Boolean Status
{
get { return status; }
set { status = value; }
}
private long userId;
public long UserId
{
get { return userId; }
set { userId = value; }
}
public Class1()
{
}
}
If your Request[sResult] is the json string you mentionned.
Try
Newtonsoft.Json.JsonConvert.DeserializeObject<List<Class1>>(Request[sResult]);
Edit, i mean :
List<Class1> myDeserializedObjList =Newtonsoft.Json.JsonConvert.DeserializeObject<List<Class1>>(Request[sResult]);

Binding to nested property

I have a class as o model:
The class Flight and flightDetails are two classes defined in the proxy of the webservice:
public class FlightView
{
public FlightView()
{
FlightDetailsElement = new FlightDetails();
Flight = new Flight();
VisibleBoarding = false;
VisibleCheckIn = false;
Visibleluggage = false;
}
public Flight Flight;
public FlightDetails FlightDetailsElement;
private bool _visibleCheckIn;
public bool VisibleCheckIn
{
get { return _visibleCheckIn; }
set { _visibleCheckIn = value; }
}
private bool _visibleBoarding;
public bool VisibleBoarding
{
get { return _visibleBoarding; }
set { _visibleBoarding = value; }
}
private bool _visibleluggage;
public bool Visibleluggage
{
get { return _visibleluggage; }
set { _visibleluggage = value; }
}
private DateTime _refreshDate;
public DateTime RefreshDate
{
get { return _refreshDate; }
set { _refreshDate = value; }
}
private string _date;
public string Date
{
get { return _date; }
set { _date = value; }
}
private string _time;
public string Time
{
get { return _time; }
set { _time = value; }
}
}
in the codebehind i set the dataxontext of the grid:
SelectedFlightView.FlightDetailsElement = e.Result;
if(!(SelectedFlightView.FlightDetailsElement.IsArrival) && !string.IsNullOrEmpty(SelectedFlightView.FlightDetailsElement.BoardingGate))
SelectedFlightView.VisibleBoarding= true;
if(!(SelectedFlightView.FlightDetailsElement.IsArrival) && !string.IsNullOrEmpty(SelectedFlightView.FlightDetailsElement.CheckInArea))
SelectedFlightView.VisibleCheckIn= true;
if ((SelectedFlightView.FlightDetailsElement.IsArrival) && !string.IsNullOrEmpty(SelectedFlightView.FlightDetailsElement.LuggageDelivery))
SelectedFlightView.Visibleluggage = true;
SelectedFlightView.RefreshDate = DateTime.Now;
SelectedFlightView.Date = SelectedFlightView.RefreshDate.ToLongDateString();
SelectedFlightView.Time = SelectedFlightView.RefreshDate.ToLongTimeString();
ContentPanelDetails.DataContext = SelectedFlightView;
My problem is when i bind in the xaml:
<TextBlock Text="{Binding FlightDetailsElement.DepartureTime}"/>
I haven't the result, but when I bind
<TextBlock Text="{Binding Time}"/> i have the result.
Any ideas please??
Regards
For the binding to work, you need to use a public property. Currently, your FlightDetailsElement is a public field. To fix your problem, just declare it as a property:
public FlightDetails FlightDetailsElement { get; set; }

Categories