2010-06-30 71 views
0

獲取集合中的WPF

<Window x:Class="Repo.MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Repo="clr-namespace:Repo" Title="Window1" Height="300" Width="300"> 
<Grid> 
<Button Click="SaVeEverythingInDatabase></Button> 
<Repo:UserControlTasks/> 

</Grid> 
</Window> 

public class UserControlTasks:userControl 

public partial class UserControlTasks: UserControl 
    { 
     public UserControlTasks() 
     { 
      InitializeComponent(); 
      LoadView(); 
     } 

    private void LoadView() 
    { 

     this.lbTasks.ItemsSource = new TaskModelView();//collectionOfTasks 

    } 

如何從在UserControlTask​​s lbTasks收集當我點擊主窗口的按鈕?

我必須補充說,我這個集合是類Student的實例的一部分,它是MainWindow的datacontext。

回答

1

在MainWindow類中創建TaskModelView並將其分配給Button控件和UserControlTask​​s控件。您需要爲此添加一個依賴屬性到UserControlTask​​s。