Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6073111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:14:06+00:00 2026-05-23T10:14:06+00:00

I have an ItemsControl and want to display some Strings from my CustomObject. It’s

  • 0

I have an ItemsControl and want to display some Strings from my CustomObject.

It’s like

String A
String B
String C

where String A and B can be multiple lines long, but C can’t. I was thinking of Height="Auto" and a DockPanel. The height of String A should be however it needs to be. With String B as well.

This is what I came up with so far:

<ScrollViewer ScrollViewer.VerticalScrollBarVisibility="Auto" Background="Black">
    <ItemsControl Name="ItemsControl1">
        <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel Orientation="Vertical" />
            </ItemsPanelTemplate>
        </ItemsControl.ItemsPanel>
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <Border BorderBrush="#FF126eb1" BorderThickness="1.5" CornerRadius="8,8,8,8" Background="#FF074e84" Width="350" Height="Auto">
                    <DockPanel Width="350" Margin="0,10,0,0" Height="Auto" Background="Transparent">
                        <Canvas DockPanel.Dock="Top" Height="Auto" Width="350" Margin="0,10,0,0">
                            <TextBlock Text="{Binding Headline}" Canvas.Left="5" Canvas.Top="5" Foreground="White" FontSize="15" FontWeight="Bold" MaxWidth="340" TextWrapping="Wrap" Height="Auto"/>
                        </Canvas>
                        <Canvas DockPanel.Dock="Top" Height="Auto" Width="350" Margin="0,10,0,0">
                            <TextBlock Text="{Binding Description}" Canvas.Left="5" Canvas.Top="20" Foreground="White" FontSize="13" MaxWidth="340" TextWrapping="Wrap" Height="Auto" />
                        </Canvas>
                        <Canvas DockPanel.Dock="Top" Width="350" Height="40" Margin="0,10,0,0" Background="Transparent">
                            <TextBlock Text="{Binding DeadlineOn, StringFormat='Deadline: {0}'}" Canvas.Left="5" Canvas.Top="5" Foreground="White"/>
                             <!-- and other controls -->
                        </Canvas>
                    </DockPanel>
                </Border>
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
</ScrollViewer>

Unfortunately only the margin property is making height for String A and B.

How can I do this, if the height of each item is unknown?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:14:06+00:00Added an answer on May 23, 2026 at 10:14 am

    There are a lot of layout elements and while this gives you a lot of choices, it can be hard to decide which layout element is the right one to use in any given situation.

    In general, a Canvas is useful for its convenient fixed positioning capabilities. It allows anything to be placed anywhere using the Canvas.Left and Canvas.Top attached properties. But because the size of a Canvas is fixed and doesn’t depend on its children, it’s difficult to use for variable-sized content. The parent of the Canvas is “insulated” from the size of the children of the Canvas, and this is actually useful in some situations.

    By contrast, a Grid is by far the flexible layout element and is useful for layout out grids with rows and columns, with or without spanning, etc. This is why its the default when you create a new Window or UserControl. But unlike a Canvas, the size of Grid, when unspecified and not stretched to the available space, is the union of the sizes of all its children.

    A Grid also has the property that if it has several children and they aren’t placed into rows or columns, then they are overlayed on top of each other, with later children being higher in the Z-order. This is just like a Canvas but without Canvas.Left and Canvas.Top, how can we finely control the position of the children?

    Let’s look at an example. Here is a Canvas with two rectangles placed side-by-side with a little space, and a Grid doing the same thing:

    <Grid>
        <StackPanel>
            <Canvas Height="120">
                <Rectangle Canvas.Left="10" Canvas.Top="10" Height="100" Width="100" Fill="Red"/>
                <Rectangle Canvas.Left="120" Canvas.Top="10" Height="100" Width="100" Fill="Green"/>
            </Canvas>
            <Grid HorizontalAlignment="Left">
                <Rectangle Margin="10,10,10,10" Height="100" Width="100" Fill="Red" HorizontalAlignment="Left"/>
                <Rectangle Margin="120,10,10,10" Height="100" Width="100" Fill="Green" HorizontalAlignment="Left"/>
            </Grid>
        </StackPanel>
    </Grid>
    

    In the first case we had to specific the height of the Canvas because it doesn’t auto-size. In the second case, we used Margin to simulate absolute positioning and the Grid size adapts to the size of its content.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have ItemsControl with DataTemplate that looks like this: I want to achieve effect
Do you know any controls inherited from the ItemsControl that have horizontal orientation of
I have some XAML <ItemsControl Name=mItemsControl> <ItemsControl.ItemTemplate> <DataTemplate> <TextBox Text={Binding Mode=OneWay} KeyUp=TextBox_KeyUp/> </DataTemplate> </ItemsControl.ItemTemplate>
I'm trying to display a list of Notes. I have an ItemsControl which is
I have created a custom ItemsControl called Toolbox. I want to be able to
I have a render-heavy item template in an ItemsControl and want to minimize the
I'm creating a custom control called FooControl derived from ItemsControl have a default style
I have some data that I want to present in a FlowDocument . This
I want to display a important list of items using an ItemsControl. The reason
On my code i have itemsControl and i want to filter the items that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.