StezPet
StezPet

Reputation: 2450

Difference between itempresenter, contenetpresenter, itemcontrol,contentcontrol

What is the significant difference between

  1. ItemPreseneter and ContentPresenter also ItemsControl and ContentControl in WPF, Please any one help me to lean the usage of this items along with some simple sample.

Upvotes: 4

Views: 2764

Answers (1)

Big Daddy
Big Daddy

Reputation: 5234

A ContentControl is used to display a one piece of content and it stretches to fill its region. An ItemsControl displays multiple items and will fill its region, but its items will occupy only the space they need.

Here's some simple code showing them both:

  <GroupBox>
    <ScrollViewer>
       <ItemsControl 
             ItemsSource="{Binding}">                    
       </ItemsControl>
    </ScrollViewer>
  </GroupBox>


  <GroupBox >
     <Border>
          <ContentControl ContentTemplate="{StaticResource YourTemplate}" Content="{Binding}" />
     </Border>
  </GroupBox>

A ContentPresenter is typically used in the ControlTemplate of a ContentControl and an ItemsPresenter is used in the template of an ItemsControl. These are the places where content/items are added.

This is a very high-level answer to a high-level question. This can get you started, but you're going to need to spend some time researching these important controls to fully understand.

Upvotes: 7

Related Questions