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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:52:44+00:00 2026-05-28T05:52:44+00:00

I created my own toolbar. Inside toolbar I have collection property to display custom

  • 0

I created my own toolbar. Inside toolbar I have collection property to display custom items:

public static readonly DependencyProperty CustomItemsProperty =
            DependencyProperty.Register("CustomItems", typeof(List<UIElement>), typeof(DitatToolbar), new PropertyMetadata(new List<UIElement>()));

        public List<UIElement> CustomItems
        {
            get { return GetValue(CustomItemsProperty) as List<UIElement>; }
            set { this.SetValue(CustomItemsProperty, value); }
        }

On one of my views I declared toolbar with one custom item:

<my:DitatToolbar
            Status="{Binding State, Converter={StaticResource ViewEditingStateToToolbarStateConverter}}"
            Mode="DataEntry">
            <my:DitatToolbar.CustomItems>
                <my:DitatToolbarButton Icon="/IDATT.Infrastructure.SL;component/Images/img_btn_calculate.png" Caption="Next&#x0d;&#x0a;Number" Index="6" Command="{Binding GetNextNumberCommand}" />
            </my:DitatToolbar.CustomItems>
        </my:DitatToolbar>

Basically, I wanted to place custom “Get next Number” button on my toolbar. Inside onApplyTemplate I call this method:

internal void BuildUi()
    {

    if (this.ButtonsStackPanel == null) return;

    this.defaultStatusVisibility = Visibility.Collapsed;
    this.defaultNavigationVisibility = Visibility.Collapsed;

    this.ButtonsStackPanel.Children.Clear();
    this.Items = new List<UIElement>();

    // Add buttons according to our work mode:
    switch (this.Mode)
    {
        case ModeType.Ok:
            this.Items.Add(this.GetNewButton(ButtonType.Ok));
            break;

        case ModeType.OkCancel:
            this.Items.Add(this.GetNewButton(ButtonType.Ok));
            this.Items.Add(this.GetNewButton(ButtonType.Cancel));
            break;

        case ModeType.Lookup:
            this.Items.Add(this.GetNewButton(ButtonType.CancelExit));
            this.Items.Add(this.GetNewButton(ButtonType.Ok));
            this.Items.Add(new DitatToolbarSeparator());
            this.Items.Add(this.GetNewButton(ButtonType.Refresh));
            break;

        case ModeType.DataEntry:
            this.defaultStatusVisibility = Visibility.Visible;
            this.defaultNavigationVisibility = Visibility.Visible;
            this.Items.Add(this.GetNewButton(ButtonType.CancelExit));
            this.Items.Add(this.GetNewButton(ButtonType.SaveExit));
            this.Items.Add(new DitatToolbarSeparator());
            this.Items.Add(this.GetNewButton(ButtonType.Cancel));
            this.Items.Add(this.GetNewButton(ButtonType.SaveClose));
            this.Items.Add(new DitatToolbarSeparator());
            this.Items.Add(this.GetNewButton(ButtonType.RenameId));
            this.Items.Add(this.GetNewButton(ButtonType.Delete));
            break;

        case ModeType.OptionsDataEntry:
            this.defaultStatusVisibility = Visibility.Visible;
            this.Items.Add(this.GetNewButton(ButtonType.CancelExit));
            this.Items.Add(this.GetNewButton(ButtonType.SaveExit));
            this.Items.Add(new DitatToolbarSeparator());
            this.Items.Add(this.GetNewButton(ButtonType.Save));
            break;

        default:
            throw new NotSupportedException("DitatToolbar Mode have to be specified");
    }

    if (this.Mode == ModeType.DataEntry || this.Mode == ModeType.OptionsDataEntry)
    {
        if (GetBindingExpression(CanEditProperty) == null)
        {
            this.SetBinding(CanEditProperty, new Binding("CanEdit") { Mode = BindingMode.TwoWay });
        }

        if (GetBindingExpression(CanDeleteProperty) == null)
        {
            this.SetBinding(CanDeleteProperty, new Binding("CanDelete") { Mode = BindingMode.TwoWay });
        }

        if (GetBindingExpression(CanRenameProperty) == null)
        {
            this.SetBinding(CanRenameProperty, new Binding("CanRename") { Mode = BindingMode.TwoWay });
        }
    }

    // Add custom buttons:
    foreach (var customItem in this.CustomItems)
    {
        var ci = customItem as IToolbarItem;
        this.Items.Insert(ci.Index, customItem);
    }

    // Insert buttons into container:
    foreach (var element in this.Items)
    {
        this.ButtonsStackPanel.Children.Add(element);
    }

    // Navigation panel visibility
    this.ShowNavigation();

    // Status panel visibility
    this.ChangeStatus();
}

My problem is that for some reason ALL toolbars in my app (various views) see this custom item that I declared only on one view. This causing issues obviously. I wonder what is wrong with my code that CustomItem dependency property becomes STATIC to whole APP?

ANSWER

Dependency property had to be declared like this:

public static readonly DependencyProperty CustomItemsProperty =
                DependencyProperty.Register("CustomItems", typeof(List<UIElement>), typeof(DitatToolbar), new PropertyMetadata(null));

And I added initialization of this property to constructor:

public DitatToolbar()
        {
            this.CustomItems = new List<UIElement>();

            this.DefaultStyleKey = typeof(DitatToolbar);
        }
  • 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-28T05:52:45+00:00Added an answer on May 28, 2026 at 5:52 am

    It looks like the default value that you have given the property in the typeMetadata parameter (new PropertyMetadata(new List<UIElement>()) is shared across all instances – i.e they will all start off with the same empty list. Use null as the default value and instead initialise an empty list per control in the constructor.

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

Sidebar

Related Questions

I have created my own Attached Property like this: public static class LabelExtension {
I created my own Custom control with its own DependencyProperty ItemsSource It dynamically creates
I created my own MyScrollbarUI class to have a custom scrollbar look in my
I created my own custom date picker consisting of an ASP TextBox, Button, and
I created my own behavior as follows: public class BoundaryExceptionHandlingBehavior : IInterceptionBehavior { public
I have created my own customized lots of architecture including n-tier layers for different
I'm writing my own extension. I've created a toolbar button. The template I used
I have created own AMI and registered it on Amazon EC2. But while AMI
I created my own ILogger implementation and register an instance via ResourceSpace.Uses.Resolver.AddDependencyInstance<ILogger>(...) inside the
I created my own custom keyboard following the the example in the sdk. Now

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.