2010-06-30 44 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。