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 928041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:56:47+00:00 2026-05-15T19:56:47+00:00

I have an control that is subclassed from ItemsControl , called WorkSheet : public

  • 0

I have an control that is subclassed from ItemsControl, called WorkSheet:

public sealed class WorkSheet : ItemsControl {

Its elements are forced to be WorkTiles:

    /// <inheritdoc />
    protected override bool IsItemItsOwnContainerOverride(object item) {
        return (item is WorkTile);
    }

    /// <inheritdoc />
    protected override DependencyObject GetContainerForItemOverride() {
        return new WorkTile();
    }

So far – so good. I want the WorkSheet to use a Canvas for presenting the WorkItems, position being determined by overriing ArrangeOverride, which is called and positions properly determined. The exact psosition is being determined in overrides. I am pretty lost in the styling, though. I simply can not get the items to appear. In The Generic.xaml, I have defined the styles. They work, but not as they should:

<Style TargetType="{x:Type local:WorkSheet}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate>
                <Border>
                    <ItemsPresenter />
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
    <Setter Property="ItemsPanel">
        <Setter.Value>
            <ItemsPanelTemplate>
                <Canvas />
            </ItemsPanelTemplate>
        </Setter.Value>
    </Setter>
    <Setter Property="ItemTemplate">
        <Setter.Value>
            <DataTemplate>
                <ContentPresenter />
            </DataTemplate>
        </Setter.Value>
    </Setter>
</Style>

Here,pretty much, in the presentation tree, the ItemsPresenter is the lowest element. The subelements of ItemsPresenter never appear. I also tried putting a Canvas into the ControlTemplate with IsItemsHost="true" – again, no items. Anyone any idea what I am doing wrong here?

Again, as explanation – I put a breakpoint into a button handler on the form and use the Visualizer to see the visual tree. The hierarchy I get is:

WorkSheet -> Border -> ItemsPresenter … and nothing below.

Obviously this means the ControlTemplate is used, but the ItemsPanel is never invoked.

  • 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-15T19:56:48+00:00Added an answer on May 15, 2026 at 7:56 pm

    Place a TargetType in your ControlTemplate as well:

    <ControlTemplate TargetType="{x:Type local:WorkSheet}">
    

    Does not work 😉

    Update 2:

    I replicated your things in a side project and you have two problems:

    First problem is the ItemTemplate setter in your Style which will trigger a StackOverflow exception (how ironic ;)). Remove the ContentPresenter, remove the whole template or use keys.

    Second problem is the GetContainerForItemOverride method. Removing this method will give me stuff on screen!

    Here is my code:

    public sealed class WorkSheet : ItemsControl
    {
        /// <inheritdoc />
        protected override bool IsItemItsOwnContainerOverride(object item)
        {
            return (item is WorkTile);
        }
    
    }
    

    And the xaml of Window with the Style:

    <Window x:Class="WpfApplication8.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:WpfApplication8="clr-namespace:WpfApplication8"
        Title="Window1" Height="300" Width="300">
    
        <Window.Resources>
            <Style TargetType="{x:Type WpfApplication8:WorkSheet}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate >
                            <Border>
                                <ItemsPresenter />
                            </Border>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
                <Setter Property="ItemsPanel">
                    <Setter.Value>
                        <ItemsPanelTemplate>
                            <Canvas />
                        </ItemsPanelTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
    
        </Window.Resources>
    
        <Grid>
            <WpfApplication8:WorkSheet x:Name="sheet" />
        </Grid>
    </Window>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a control that is created like so: public partial class MYControl :
I have a custom control that inherits from WebControl and implements IValidator, but I
I currently have a control that called MyGridview that inherits Gridview. It has a
I have a class called 'Inventory' that has two subclasses, 'Drink' and 'Condiment'. They
I have subclassed a graphics control that takes a device context handle, HDC, as
I have a control that, upon postback, saves form results back to the database.
I have a control that is basically functioning as a client-side timer countdown control.
I have a control that I'm writing where I want to turn off .NET's
I have an ASPX page and on this page I have a control that
I have a custom control that implements IPostBackEventHandler. Some client-side events invoke __doPostBack(controlID, eventArgs).

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.