Hajar Ibrahiem
Hajar Ibrahiem

Reputation: 25

Control Binding Times in XAML

I want To know if there is a way to Define how many times a Grid can bind to a list ?

for example , If I have a list of 20 elements , can I restrict the Binding To just the First Ten elements of the list .

the problem is that I use the same list for 2 different controls , I need the first control to bind to the entire all list , and the second to bind to the first 10 elements . so is there is anyway to do this from XAML ?

thanks :))

Upvotes: 0

Views: 40

Answers (2)

Filipe Miguel
Filipe Miguel

Reputation: 519

On your code-behind, or view-model, or wherever said list is, just set a property that exposes what you want:

public IEnumerable<something> MyTopElements
{
    get { return myList.Take(10); }
}

and bind to that instead

Upvotes: 1

Muds
Muds

Reputation: 4116

in that case

public List<something> MyTopItems    
{
    get { return myItems.Take(10); }
}

public List<something> MyItems    
{
    get { return myItems; }
}

Upvotes: 0

Related Questions