开发者

Get collection from subusercontrol in WPF

I have

<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

    }

How to get collection from lbTasks in UserControlTasks when I click button on MainWindow?

I must add that I this collection is a part of instances of class Student which is datacontext of MainWindow.


Create TaskModelView in MainWindow class and assign it to Button control and UserControlTasks control. You will need to add a dependecy property for this to UserControlTasks.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜