我有一个类作为模型: Flight和flightDetails类是在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; }
}
}
在代码隐藏中我设置了网格的dataxontext:
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;
我的问题是当我绑定xaml时:
<TextBlock Text="{Binding FlightDetailsElement.DepartureTime}"/>
我没有结果,但是当我绑定
时 <TextBlock Text="{Binding Time}"/>
我有结果。
有什么想法吗?
此致
答案 0 :(得分:1)
要使绑定起作用,您需要使用公共属性。目前,您的FlightDetailsElement
是公共字段。要解决您的问题,只需将其声明为属性:
public FlightDetails FlightDetailsElement { get; set; }