2010-01-16 43 views
0

我需要更改我的xaml /代碼才能使properties => SchoolclassName and LessonName能夠在TextBlock上工作?我沒有得到任何綁定錯誤,但我沒有看到任何顯示:沒有綁定錯誤,但仍然綁定不顯示任何東西?

<Grid Margin="20" Height="300" Background="AliceBlue"> 
    <ListView ItemsSource="{Binding Timetable}"> 
     <ListView.View> 
      <GridView>      
       <GridView.Columns>        
        <GridViewColumn Header="Period" 
            DisplayMemberBinding="{Binding LessonPeriod}"/> 
        <GridViewColumn Header="Monday"> 
         <GridViewColumn.CellTemplate> 
          <DataTemplate> 
           <ListView ItemsSource="{Binding Monday}"> 
            <ListView.ItemTemplate> 
             <DataTemplate> 
              <StackPanel Width="150" Orientation="Horizontal"> 
               <TextBlock Text="{Binding LessonName}"/> 
               <TextBlock Text=" "/> 
               <TextBlock Text="{Binding SchoolclassName}"/> 
              </StackPanel> 
             </DataTemplate> 
            </ListView.ItemTemplate> 
           </ListView> 
          </DataTemplate> 
         </GridViewColumn.CellTemplate> 
        </GridViewColumn> 
       </GridView.Columns> 
      </GridView> 
     </ListView.View> 
    </ListView> 
</Grid> 


public partial class Window1 : Window 
{ 
    List<TimetableEntry> _timetable = new List<TimetableEntry>(); 

    public List<TimetableEntry> Timetable 
    { 
     get { return _timetable; } 
     set { _timetable = value; } 


    public Window1() 
    { 
     InitializeComponent(); 

     _timetable.Add(new TimetableEntry() 

          { 
           LessonPeriod = "Period 1", 
           Monday = new TimetableDay() 
           { 
            LessonName = "Maths" , 
            SchoolclassName = "1c",           
           }, 

          } 
         ); 

     this.DataContext = this; 
    } 


    public class TimetableEntry 
    { 
     public string LessonPeriod { get; set; } 
     public TimetableDay Monday { get; set; } 
     public TimetableDay Tuesday { get; set; } 
     public TimetableDay Wednesday { get; set; } 
     public TimetableDay Thursday { get; set; } 
     public TimetableDay Friday { get; set; } 
     public TimetableDay Saturday { get; set; } 
     public TimetableDay Sunday { get; set; } 
    } 

    public class TimetableDay 
    { 
     public string LessonName { get; set; } 
     public string SchoolclassName { get; set; } 
    } 

    public class TimetableLesson 
    { 
     public string LessonName { get; set; } 
     public string SchoolclassName { get; set; } 
     public DateTime LessonTime { get; set; } 
    } 
} 

回答

1

您設置內部ListView的的ItemsSource是週一財產。但是星期一是TimetableDay,而不是集合,所以沒有用於列舉內部列表視圖的「列表」。

你可能只是想擺脫內心的ListView,並直接擁有的DataTemplate綁定關TimetableEntry,利用週一屬性的子屬性:

<GridViewColumn.CellTemplate> 
    <DataTemplate> 
    <StackPanel Width="150" Orientation="Horizontal"> 
     <TextBlock Text="{Binding Monday.LessonName}" /> <!-- note multipart path --> 
     <TextBlock Text=" " /> 
     <TextBlock Text="{Binding Monday.SchoolclassName}" /> 
    </StackPanel> 
    </DataTemplate> 
</GridViewColumn.CellTemplate> 
+0

是你是對的,當我擺脫內部ListView它的作品!但我需要該ListView,因爲我想添加另外6個ListView.ItemTemplates爲每個工作日添加6個列: 星期一,星期二,星期三...... 我該如何處理該問題而不再引入List <>? – msfanboy

+0

ups對不起,我的失敗我忘了添加星期二等GridViewColumn,現在的作品! – msfanboy

+0

啊我真的太快了,我的檢查和測試; P 現在的問題是,在我現在使用的DataGrid中,而不是一個ListView,課程開始於星期二,他們在星期一停止... 請參閱圖像清楚: [URL = http://img64.imageshack.us/i/classn.png/] [IMG] http://img64.imageshack.us/img64/9691/classn.png [/ IMG ] [/ URL] 星期二的課程在星期一開始後直接開始。 我怎樣才能讓課程在星期二的1,2,3小時開始? – msfanboy

相關問題