2012-10-24 178 views
1

我有一個類如鄰模型: 類飛行和flightDetails是在web服務的代理定義兩類:綁定到嵌套屬性

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; } 
     } 

    } 
設定在I網格的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}"/>我有結果。

有什麼想法嗎?

Regards

+0

是否FlightDetails有一個屬性DepartureTime? –

+0

是的,當我改變datacontext像這樣'ContentPanelDetails.DataContext = SelectedFlightView.FlightDetailsElement;'和我使用''我有結果 – user1428798

回答

1

對於綁定工作,您需要使用公共屬性。目前,您的FlightDetailsElement是一個公共領域。要解決您的問題,只需將其聲明爲屬性:

public FlightDetails FlightDetailsElement { get; set; }