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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:58:55+00:00 2026-05-25T10:58:55+00:00

Solved it myself. It was the way I initialised the Settings collection. Specifying a

  • 0

Solved it myself. It was the way I initialised the Settings collection. Specifying a default when registering it as a DependencyProperty causes all of the Settings to refer to the same collection object. Adding a constructor to Category and explicitly initialising Settings resolves the issue.


A class Category specifies a name and a collection of Settings objects.

using System.Collections.ObjectModel;
using System.Windows;

namespace CasEdit
{
  public class Categories : ObservableCollection<Category> { }

  public class Category : DependencyObject
  {
    public string Caption
    {
      get { return (string)GetValue(CategoryProperty); }
      set { SetValue(CategoryProperty, value); }
    }
    public static readonly DependencyProperty CategoryProperty =
        DependencyProperty.Register("Caption", typeof(string), typeof(Category), 
        new UIPropertyMetadata("Category name not set"));
    public Settings Settings
    {
      get { return (Settings)GetValue(SettingsProperty); }
    }
    public static readonly DependencyProperty SettingsProperty =
        DependencyProperty.Register("Settings", typeof(Settings), typeof(Category), 
        new UIPropertyMetadata(new Settings()));
  }
}

The following XAML defines templates, UI and some test data.

<Window x:Class="CasEdit.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:CasEdit="clr-namespace:CasEdit"
        Title="MainWindow" Height="350" Width="525" >
  <Window.Resources>
    <HierarchicalDataTemplate DataType="{x:Type CasEdit:Category}" ItemsSource="{Binding Settings}">
      <StackPanel Orientation="Horizontal">
        <TextBlock Text="{Binding Caption}" />
        <Button Content="Gratuitous button" Margin="3" Click="Button_Click"/>
      </StackPanel>
    </HierarchicalDataTemplate>
    <DataTemplate DataType="{x:Type CasEdit:Setting}" >
      <StackPanel Orientation="Horizontal">
        <TextBlock Text="{Binding Caption}" Margin="3" />
        <TextBlock Text="{Binding Template}" Margin="3" />
        <TextBox Text="{Binding Editor}" Margin="3" />
        <TextBlock Text="{Binding CasDevice}" Margin="3" />
      </StackPanel>
    </DataTemplate>
    <CasEdit:Categories x:Key="cats">
      <CasEdit:Category Caption="1st category">
        <CasEdit:Category.Settings>
          <CasEdit:Setting Caption="Setting 1-1" />
          <CasEdit:Setting Caption="Setting 1-2" />
        </CasEdit:Category.Settings>
      </CasEdit:Category>
      <CasEdit:Category Caption="2nd category" >
        <CasEdit:Category.Settings>
          <CasEdit:Setting Caption="Setting 2-1" />
        </CasEdit:Category.Settings>        
      </CasEdit:Category>
      <CasEdit:Category Caption="3rd category" >
        <CasEdit:Category.Settings>
          <CasEdit:Setting Caption="Setting 3-1" />
        </CasEdit:Category.Settings>        
      </CasEdit:Category>
    </CasEdit:Categories>
  </Window.Resources>
  <Grid>
    <TreeView x:Name="tree" ItemsSource="{Binding Source={StaticResource cats}}" />
  </Grid>
</Window>

You would expect a tree like this

  • 1st category
    • Setting 1-1
    • Setting 1-2
  • 2nd Category
    • Setting 2-1
  • 3rd category
    • Setting 3-1

but what I get is this

Screen snap

which is very confusing. Where have I gone astray, that each category shows all of the settings?

  • 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-25T10:58:56+00:00Added an answer on May 25, 2026 at 10:58 am

    The last parameter here is telling making it so that every instance of Category has it’s Settings property initialized to point to the same object:

    public static readonly DependencyProperty SettingsProperty =   
            DependencyProperty.Register("Settings", typeof(Settings), typeof(Category),    
            new UIPropertyMetadata(new Settings()));   
    

    Instead, do this:

        public static readonly DependencyProperty SettingsProperty =
            DependencyProperty.Register("Settings", typeof(Settings), typeof(Category),
            new UIPropertyMetadata(null));
        public Category()
        {
            Settings = new Settings();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Edit: I have solved this by myself. See my answer below I have set
EDIT: Solved this myself - obviously won't work as sorting the dataTable doesn't sort
i have portions of my program that require administrative access (settings that affect all
there's this interesting problem i can not solve myself. I will be very glad,
SOLVED: Nevermind, the links were visited, and the border definition was missing for visited
Solved I actually found out what is going on here. Turns out it was
solved: IstBestellwert = grouped.Sum(o => (double)o.SollMenge * (double)o.Preis) works My SQL Statment SELECT ABId,
SOLVED in the last answer im getting following error, dunno where and why? cause
@Solved The two subquestions I have created have been solved (yay for splitting this
SOLVED. Code has been edited to reflect solution. Given the following GridView : <asp:GridView

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.