What is the equivalent of the ASP.NET Repeater in WPF?
The ASP.NET repeater is a great control for creating an arbitrary templated look for lists of data in ASP.NET web applications. WPF's databinding bears a great deal of similarity to the templating support found in the repeater, taking the power of templating even further by allowing templates to be defined as resources and re-used in multiple contexts, and in lots of different types of controls. However in spite of this there is no Repeater control in WPF.
Sample Repeater (from MSDN)
<asp:Repeater id="Repeater1" runat="server">
<HeaderTemplate>
<table border="1">
<tr>
<td><b>Company</b></td>
<td><b>Symbol</b></td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td> <%# DataBinder.Eval(Container.DataItem, "Name") %> </td>
<td> <%# DataBinder.Eval(Container.DataItem, "Ticker") %> </td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
How can you replicate the functionality of the repeater in WPF? It turns out this is quite easy using an ItemsControl. ItemsControl is the base type that lots of list-like controls in WPF like ListBox, ComboBox and Menu which inherit from it either directly or indirectly. ItemsControl is also the parent to some list-like controls you might not expect such as the toolbar (which is really just a list of buttons and other controls, usually laid out horizontally) and StatusBar (once again, usually just a kind of horizontal list of controls). In spite of its fairly fundamental nature to lots of the usual suspects in the WPF controls namespace it isn't an abstract type and can be created in markup and bound like this:
ItemsControl Xaml Code
<ItemsControl ItemsSource="{Binding}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<!-- apply additional customizations for
the items here in the template -->
<TextBlock Text="{Binding}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
The <DataTemplate> element allows us to specify how we want each item the ItemsControl is bound to, and the ItemsSource property on the ItemsControl populates the bound items from the data context (I'm assuming for the purposes of this demo that the stuff you want to bind to is in there). Another thing you may wish to do with the ItemsControl is to place it inside of a ScrollViewer control. The ASP.NET repeater generates HTML which is hosted in the browser, which handles showing a scroll-bar if the document is longer than can be displayed on a single screen. WPF Windows and Pages don't default to this way of operating, and thus you probably want to add the scroll viewer if more items are added to the ItemsControl than can be displayed inside the Window or Page.
Here is a complete page showing the list of binding modes available in WPF displayed in an ItemsControl. The ItemsControl has an ItemsPanel property that the bound items are layed out in. The default is a StackPanel, which is they type of panel you would want to reproduce the functionality of the ASP.NET Repeater. In this example below we've used the UniformGrid instead to control the layout of the items being bound. You can click here to run this page in your browser.
<Page
xmlns="
http://schemas.microsoft.com/winfx/2006/xaml/presentation
"
xmlns:x="
http://schemas.microsoft.com/winfx/2006/xaml
"
xmlns:d="clr-namespace:System.Windows.Data;assembly=PresentationFramework"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
>
<Page.Resources>
<ObjectDataProvider MethodName="GetValues" ObjectType="{x:Type sys:Enum}" x:Key="bindingNames">
<ObjectDataProvider.MethodParameters>
<x:Type TypeName="d:BindingMode"/>
</ObjectDataProvider.MethodParameters>
</ObjectDataProvider>
</Page.Resources>
<ItemsControl ItemsSource="{Binding}" DataContext="{StaticResource bindingNames}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid IsItemsHost="True" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<!-- apply additional customizations for the items here in the template -->
<TextBlock Text="{Binding}" FontSize="22"
Margin="5" Foreground="#feca00" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Page>
Categories:
Comments:
#
Transitions when changing the ItemsPanel
posted by
Peter
on
1/18/2008 11:26:39 PM
:
I'm building a app with different views of the same datacollection. I'm also using the ItemsPanel prop. of the ItemsControl to switch them. I would like to build a transition, where my elements move to the new begining setup of the view i like to switch to.
Do you have any idea how to realize that?
#
Good
posted by
thomas
on
9/21/2009 10:24:56 AM
:
Good but asp.net repeater is better.
#
christian louboutin sale
posted by
christian louboutin sale
on
10/27/2009 4:41:35 PM
:
Bing is a really overlord!! support Bing~~
#
links of london
posted by
links of london
on
10/27/2009 7:25:37 PM
:
It was a very nice idea! Just wanna say thank you for the information you have shared. Just continue writing this kind of post. I will be your loyal reader. Thanks again.
#
support
posted by
hanyujoys
on
11/10/2009 2:53:27 PM
:
Support of the Lou Zhu, Lou Zhu worked hard
Signature--------------------------------------------------------------------------------------------------------------------
Nothing is impossible for a willing heart.
[url=
http://www.uggshelf.com/Products.html][color=black]ugg boots[/color][/url]
Signature--------------------------------------------------------------------------------------------------------------------
Nothing is impossible for a willing heart.
[url=
http://www.uggshelf.com/UGG-Bailey-Button/View-all-products.html][color=black]ugg bailey button[/color][/url]
#
timberland kids boots
posted by
classic timberland boots
on
11/12/2009 5:14:04 PM
:
After seven days spent in the classic timberland boots meadow the souls had to set out again on the eighth and came in four days to a timberland kids boots place from which they could see a shaft of light stretching from above straight through earth and heaven, like a discount timberland boots pillar, closely resembling a rainbow, only brighter and clearer; this they reached after a timberland womens boots, further day's journey and saw there in the timberland men’s boots middle of the light stretching from the heaven the ends of the bonds of it; for this light is the bond of heaven and holds its whole circumference together, like the swifter of a trireme.
http://www.officialtimberland.com/products_new.html
#
professional shoes
posted by
nike shox shoes
on
11/12/2009 9:50:07 PM
:
Flat feet is a mbt shoes growing problem. A lot of professional shoes people are getting pronation in the mbt usa ankle which relates to knee pain mbt uk which relates to knee injury, which relates to the hip to the back. It all nike shox shoes relates to everything, it all starts at your feet.a sports mbt outlet and prada shoes recreation manager and former Australian Olympic volleyballer, also recommends people spend money on mbt footwear to reduce the risk of injury.
http://www.airjordanshow.com/
#
www.nikejordansale.com
posted by
mbt shoes clearance
on
11/21/2009 5:29:56 AM
:
welcome to our website:
http://www.nikejordansale.com ,we hope become your reliable online cheap goods supplier in china.Authentic goods with original box,we insists tha"Customer the highest,Quality first!"Our products include mbt shoes clearance,ugg classic tall sale,mens air jordan shoes and other cheap goods.We are looking forward to building sincere and long-term business relationships with you.
#
uggs on sale
posted by
uggs on sale
on
11/25/2009 7:55:47 PM
:
S11125L2UGG popular star in Hollywood several years ago had spread to uggs on sale mean the improvement of people's lives and as a force to follow the ugg boots uk star to wear UGG's wave of school is becoming everyone's most interesting content. Here Ai Sa Kaka on the boots on sale popular UGG fashion for up to one sorted out a set of current Hollywood's most sought-after actress of the ugg bailey boots UGG shoes, street beat, let's take a look at what they are wearing UGG's Bar.
http://www.uggbootssaleonline.com
#
tiffany jewelry
posted by
tiffany jewelry
on
11/26/2009 12:14:29 AM
:
tiffany jewelry
Tiffany Necklaces
Tiffany Earrings
Tiffany Rings
Tiffany Bracelets
#
timberland work boots
posted by
timberland work boots
on
11/26/2009 2:29:45 AM
:
S11125I2 The son of wealthy and influential Athenian parents, Plato began his timberland chukka boots philosophical career as a student of Socrates. When the master died, Plato travelled timberland waterproof boots to Egypt and Italy, studied with students of Pythagoras, and spent timberland work boots several years advising the ruling family of Syracuse. Eventually, he returned timberland custom boots to Athens and established his own school of philosophy at the Academy.For students enrolled there, Plato tried timberland high top boots both to pass on the heritage of a Socratic style of thinking and to guide their progress through mathematical learning to the achievement of abstract philosophical truth.
http://www.officalsale.com/specials.html
#
http://www.ladyugs.com/specials.html
posted by
Ugg Classic Boots
on
11/26/2009 1:21:04 PM
:
S11125H2 Towering genius disdains a beaten path with discount ugg boots. It seeks regions hitherto unexplored.A man may lead a horse to the water, but he cannot make it drink and walk with ugg classic tall .Victory wil not come to ugg lo pro button unless I go to ugg classic cardy.Goals determine what you are going to ,for example, buy ugg knightsbridge.
http://www.ladyugs.com/specials.html
#
http://www.ladyugs.com/specials.html
posted by
Ugg Classic Boots
on
11/26/2009 1:21:05 PM
:
S11125H2 Towering genius disdains a beaten path with discount ugg boots. It seeks regions hitherto unexplored.A man may lead a horse to the water, but he cannot make it drink and walk with ugg classic tall .Victory wil not come to ugg lo pro button unless I go to ugg classic cardy.Goals determine what you are going to ,for example, buy ugg knightsbridge.
http://www.ladyugs.com/specials.html
#
uggs on sale
posted by
uggs on sale
on
11/28/2009 7:35:15 PM
:
S11128L2UGG popular star in Hollywood several years ago had spread to uggs on sale mean the improvement of people's lives and as a force to follow the ugg boots uk star to wear UGG's wave of school is becoming everyone's most interesting content. Here Ai Sa Kaka on the boots on sale popular UGG fashion for up to one sorted out a set of current Hollywood's most sought-after actress of the ugg bailey boots UGG shoes, street beat, let's take a look at what they are wearing UGG's Bar.
http://www.uggbootssaleonline.com
#
ed hardy clothing,ed hardy coat
posted by
edfashionclothes
on
12/5/2009 1:34:53 PM
:
Thank you for the message!With the advent of Christmas and to enlarge and refresh our market,we encourage both newcomers and loyal customers to browse our ugg boots sale promotions.The price of our ugg classic argyle knit,ugg bailey button or ugg classic cardy are lowest than anytime and anywhere,there are also lots ugg mayfaire boots and ugg sundance II boots that you can choose.If the goods you choose are more than $100,you can pick up a gift Free.Time Limited, Don't be hesitation,pick up your favorate goods,Free Shipping & Fast Delivery.
http://www.edfashionclothes.com/
#
ugg bailey button,ugg classic argyle knit boots
posted by
nikeaf1jordanshoes
on
12/5/2009 1:35:04 PM
:
Good job!Thank you for your message!It help me so much! Christmas is coming,there are big sales promotions on
http://www.nikeaf1jordanshoes.com/,ugg bailey button and ugg classic argyle knit boots on our site are lower than ever,you may be intersting in ugg mayfaire boots or ugg nightfall boots,ugg sundance II ,come on to choose your favorate goods!
#
ugg bailey button,ugg classic Boots
posted by
uggsnowbootsbest
on
12/5/2009 1:35:14 PM
:
Thank you for the great job!In order to?welcome to Christmas, recently,our company is on ugg boots promotional sales and the?prices of all products such as?ugg sundance II boots or ugg bailey button boots are lower than any time!And the biggest surprise is that?you can buy one get one free,that?is once you buy an ugg mayfaire boots , ugg coquette, or ugg classic crochet,you can get one gift for free.Don't hesitate, to get?a free present, check it on
http://www.uggsnowbootsbest.com/
#
ugg classic tall
posted by
ugg classic cardy
on
12/17/2009 8:00:58 PM
:
1217htf Progress is the activity of cheap ugg boots today and the assurance of uggs sale tomorrow .The world can be changed as discount ugg boots by man's endeavor for ugg classic cardy, and that this endeavor can lead to something new ugg classic tall and better ugg bailey button . Remember ugg classic mini,The man who has made up his mind to win ugg classic short will never say 'impossible' for uk ugg boots . For victory won't come to me with ugg classic crochet unless I go to it for usa ugg boots.
http://www.ugganow.com/
#
Cardy Ugg Boots
posted by
Cardy Ugg Boots
on
1/8/2010 4:35:06 PM
:
slLAH100108 I think this blog is good,so now I wanna introduce mbt to you.{{[MBT Chapa shoes->
http://www.cutembt.com/mbt-chapa-shoes-c-71.html]}} are a growing and popular anti-shoe inspired by the Masai people. The Masai people are known for their athletic posture and gait. It is known that none of the Masai people struggle with any back pain due to walking on hard surfaces,so they try {{[MBT Women M.Walk shoes->
http://www.cutembt.com/mbt-women-mwalk-shoes-c-42.html]}}. At last,they found the benefit of MBT Women M.Walk shoes, they trust mbt shoes.
#
uggs on sale
posted by
ugg boots
on
1/26/2010 12:00:41 PM
:
100126SLLYH
Our greatest glory uggs boots consists not in never falling but in rising every ugg classic tall time we fall.It is not enough ugg classic boots to be industrious, so are the ants. What are you industrious about ugg classic argyle knit? You have to believe in yourself. That's the ugg bailey button secret of sucess. A wise man never loses anything if he has himself. To be without some of the things you want is an indispensable part of happiness.
http://www.4ezlive.com/
#
replica gucci
posted by
replica gucci
on
3/22/2010 4:40:52 PM
:
His two children, ages 4 and 7, were wounded and transported to a hospital, the attorney general's office replica hermes said. Salcido's wife was traveling in another vehicle, which was not attacked, Reyes hublot replica said. In Washington, President Obama and Secretary of State Hillary Clinton replica hublot watch anger. The president is deeply saddened and outraged by the news of replica hublot watches the brutal murders of three people associated with the United States Consulate General in Ciudad replica hublot Juarez, National Security Council spokesman Mike Hammer.
http://www.overwatches.com/alain_silberstein-watches.htmlhttp://www.overwatches.com/armani-watches.html
#
jaeger lecoultre
posted by
jaeger lecoultre
on
3/24/2010 4:14:06 PM
:
In the other theater, The Pacific replica jaeger lecoultre watches makes painfully clear in its early episodes, the Marines that it follows had no idea what they were getting into. On the one hand jaeger lecoultre replica, the replica jaeger lecoultre watches war was simple: Japan attacked the U.S. at Pearl Harbor, and now we were going to get those bastards back. On the other hand, they were going to be introduced to a kind of war they had scarcely imagined, on replica jaeger lecoultre watch islands they didn't know, at a replica jaeger lecoultre watches cost they could not conceive.
http://www.overwatches.com/jaeger_lecoultre-watches.html
#
replica lv
posted by
replica lv
on
3/26/2010 1:28:03 PM
:
Pronto, an environmental studies major who replica lv watch works each summer as a forest firefighter, agreed. Apart from remembering to lower the toilet seat, he said, living with a woman lv replica friend is not much different from rooming with a man. As far replica lv watch as I'm concerned, a roommate is a roommate, he said. Although the number of participants remains small, gender-neutral housing has gained replica lv watch attention as the final step replica lv watch in the integration of student housing.
http://www.overwatches.com/lv-watches.html
#
replica miscellaneous
posted by
replica miscellaneous
on
3/27/2010 3:13:34 PM
:
Pitzer, which has about a dozen students participating this year, avoids such limits out of concern that they may marginalize students, said Chris Brunelle, director of residence miscellaneous replica life. Pitzer miscellaneous replica housing applications ask miscellaneous replica whether students prefer a roommate to be woman, man, other, or have no preference. Or students replica miscellaneous can request to live together, as Eland and Pronto did replica miscellaneous watch after losing replica miscellaneous their original roommates.
http://www.overwatches.com/miscellaneous-watches.html
#
Mbt shoes
posted by
Mbt shoes
on
3/29/2010 1:00:22 PM
:
MBT Shoes Sale offer powerful training shoes Cheap MBT Shoes.
Mbt shoes made from high quality Nappa leather are strong and enduring.mbt shoes Best Prices available at cheap mbt shoes help to build body
#
replica watches
posted by
replica watches
on
4/5/2010 11:14:36 AM
:
But what about regular moviegoers would they even notice replica watches anything amiss with the movie’s 3-D? It’s no small question for replica watches Hollywood. With at least 70 movies replica watches in the 3-D pipeline including many similar replica watches conversion projects studios and theater owners are betting replica watches heavily that audiences will snap up increasingly expensive replica watches 3-D tickets.
http://www.watchvisa.com
#
replica watches
posted by
replica watches
on
4/5/2010 12:27:20 PM
:
I thought the 3-D quality was really good, said Eric Shimp as replica watches he left a showing of Clash of the Titans at the AMC Century City 15 in Los replica watches Angeles. Mr. Shimp, who works in the automotive industry, added replica watches, The ticket prices are ridiculous, but it does leave replica watches you feeling like you’ve just seen a spectacle. Sharle Kochman, a cosmetologist, said replica watches as she left the theater that she thought the 3-D quality was on a par with Avatar.
http://www.overwatches.com
#
Links of London Jewellery
posted by
Links of London Jewellery
on
4/8/2010 2:27:55 PM
:
Their eyes and ears take in all sights and sounds hazily, without concentration and with little appreciation. It is the same old story of not being grateful for what we have until we lose it, of not being conscious of health until we are ill.
#
replica rolex watches
posted by
replica rolex watches
on
4/10/2010 3:56:29 PM
:
For the most part, I have done a pretty good job. I once told a replica watches local pharmacist who charged rolex watch me twice to send the same fax that if he didn't give me my money back, I would never come into rolex watch his store again. He thought it was an idle threat. Twenty years later, I was still rolex watches snubbing him, right up until the day he went to prison for Medicaid fraud.
http://www.watchessell.com/product.php?id=4&categories_id=36
#
Replica BRM Watches
posted by
Replica BRM Watches
on
4/15/2010 1:48:04 PM
:
I am willing to give you a big surprise: <a href=
http://www.replica-brand-watches.com">
http://www.replica-brand-watches.com">
http://www.replica-brand-watches.com">
http://www.replica-brand-watches.com title=replica brand watches>replica-brand-watches.com</a> is <a href=
http://www.offerreplicawatches.com title=offer replica watches>offer replica watches</a>. I bought an <a href=
http://www.replica-brand-watches.com">
http://www.replica-brand-watches.com">
http://www.replica-brand-watches.com">
http://www.replica-brand-watches.com/Replica-iwc-watches_g1179 title=replica IWC Watches>replica IWC Watches</a> a week ago from this site. They sell a wide range of <a href=
http://www.replica-brand-watches.com">
http://www.replica-brand-watches.com">
http://www.replica-brand-watches.com">
http://www.replica-brand-watches.com title=replica watches>replica watches</a>, such as <a href=
http://www.replica-brand-watches.com">
http://www.replica-brand-watches.com">
http://www.replica-brand-watches.com">
http://www.replica-brand-watches.com/Replica-chanel-watches_g1138 title=Replica Chanel Watches>Replica Chanel Watches</a>, <a href=
http://www.replica-brand-watches.com">
http://www.replica-brand-watches.com">
http://www.replica-brand-watches.com">
http://www.replica-brand-watches.com/Replica-brm-watches_g1172 title=replica B.R.M Watches>replica B.R.M Watches</a> on sale, <a href=
http://www.replica-brand-watches.com">
http://www.replica-brand-watches.com">
http://www.replica-brand-watches.com">
http://www.replica-brand-watches.com/Replica-rolex-watches_g1190 title=replica Rolex watches>replica Rolex watches</a> for sale, <a href=
http://www.replica-brand-watches.com">
http://www.replica-brand-watches.com">
http://www.replica-brand-watches.com">
http://www.replica-brand-watches.com/Replica-omega-watches_g1184 title=replica Omega watches>replica Omega watches</a>, buy <a href=
http://www.replica-brand-watches.com">
http://www.replica-brand-watches.com">
http://www.replica-brand-watches.com">
http://www.replica-brand-watches.com/Replica-christian-dior-watches_g1769 title=replica Christian Dior watches>replica Christian Dior watches</a>, sell <a href=
http://www.replica-brand-watches.com">
http://www.replica-brand-watches.com">
http://www.replica-brand-watches.com">
http://www.replica-brand-watches.com/Replica-gucci-watches_g1682 title=replica Gucci watches>replica Gucci watches</a>, <a href=
http://www.replica-brand-watches.com">
http://www.replica-brand-watches.com">
http://www.replica-brand-watches.com">
http://www.replica-brand-watches.com/Replica-cartier-watches_g1174 title=replica Cartier Watches>replica Cartier Watches</a>, <a href=
http://www.replica-brand-watches.com">
http://www.replica-brand-watches.com">
http://www.replica-brand-watches.com">
http://www.replica-brand-watches.com/Replica-richard-mille-watches_g1189 title=replica Richard Mille Watches>replica Richard Mille Watches</a>, Wholesale <a href=
http://www.replica-brand-watches.com">
http://www.replica-brand-watches.com">
http://www.replica-brand-watches.com">
http://www.replica-brand-watches.com/Replica-ebel-watches_g1176 title=Replica Ebel Watches>Replica Ebel Watches</a> and so on. And I also hear that they also <a href=
http://www.lovedvddisk.com">
http://www.lovedvddisk.com title=sell DVD Sets>sell DVD Sets</a> which are mainly new and existing. Now, many companies are promoting their products. The more important, their price is very reasonable. If you want to buy the watches and <a href=
http://www.lovedvddisk.com">
http://www.lovedvddisk.com title=DVD Sets>DVD Sets</a> now, it is not a bad choice for you to buy from <a href=
http://www.replica-brand-watches.com">
http://www.replica-brand-watches.com">
http://www.replica-brand-watches.com">
http://www.replica-brand-watches.com title=replica brand watches>replica-brand-watches.com</a> and <a href=
http://www.lovedvddisk.com">
http://www.lovedvddisk.com/ title=dvd box set>lovedvddisk.com</a> on 99172381231231128
#
watches order
posted by
rolex watches
on
4/16/2010 5:24:57 PM
:
People usually say :"Seeing is believing." Each attempt has a corresponding gain, in part or obvious, or vague. At least we have the kind of satisfaction After I bought this watch ,in a sense,it means a great deal to me.
<a href="
http://www.tt88times.com/">rolex watches</a>
#
Thanks for sharing
posted by
.NET
on
4/17/2010 7:13:45 PM
:
Thanks for sharing the information. That's a awesome article you posted. I will come back to read some more.
#
rolex watches
posted by
rolex watches
on
4/26/2010 12:30:20 PM
:
That’s all I was asking for. Nothing more, nothing less. Celtics coach replica rolex watches Doc Rivers didn’t see a replay of the incident until yesterday morning, and he thought Richardson was out of line for standing over Pierce as he lay prone. He had no business over replica rolex there, Rivers said. We had replica watches a guy on the floor injured. There was no reason for him to be there. And then, going by all reports, not only just the crowding, but it was the taunting.
http://www.watchesmine.com/rolex-watches.html