last day (18 days later) » 

7:31 PM
0
A: TreeView not displaying children stored in data

J.H.You don't have enough code for me to know exactly how you have things set up. I tried to keep it similar to what you already have. I think you should be able to figure it out though. Screenshot: XAML: <Window x:Class="WpfApplication9.MainWindow" xmlns="http://schemas.microsoft.com/winfx/...

 
Why do I need to set an ItemTemplate? I don't have one set up in any of my other TreeViews and they are working just fine.
 
Do they have children too? IDK.. I just took a TreeView w/children that I had in some of my code and adjusted it.
 
Yes they have children as well
 
Are you adding them in code? Or with a binding? AFAIK, you have to have a HierarchicalDataTemplate for the binding.
 
Yes I'm adding them with newNode.Children.Add(new TreeViewDataModel () { DisplayName = nodeName});, upon creation of the main parent node. I think you are on the right track, I did forget to create a HierarchicalDataTemplate for this treeView so I just created one. Unfortunately, still no children.
 
7:31 PM
I added an Alt-way of doing it, with the hierachicaldatatemplate as a resource.
My first chat.
 
This is your first chat?
 
Yeah
 
Nice =)
Welcome, haha
 
lol
 
I'm thinking the problem is with my StringItem class, let me explain why
 
7:32 PM
k
you want to paste the class?
 
I have 2 other treeViews, one has it's DisplayName property set as a string and it works fine. The other has it's DisplayName property set as MultiItemStringwhich is another class similar to StringItem that has a "value" property
Here is StringItem:
     public class StringItem : INotifyPropertyChanged
    {
        private readonly string _key;
        readonly bool _resourceKey;

        private int _id;

        public StringItem(string key, bool resourceKey = true)
        {
            _key = key;
            _resourceKey = resourceKey;

            LanguageChange.LanguageChagned += (sender, args) => RaisePropertyChanged("");
        }

        public string Key
        {
            get { return _key; }
        }

        public string Value
So I'm thinking that because MultiItemString works fine in the other TreeView, that Stringitem is the problem
 
I copied that into my code, and of course its blank because I don't have the application.current.resources[_key] in my app.... so, I changed it to "Resource for key: " + _key; and it shows that string in the treeview (parent and child)
Also, I had to comment out that "LanguageChanged +=" line
 
That's okay, you don't have the localization strings in your code
 
If you change it to this, does it still not show anything?
    public string Value
    {
        get
        {
            if (_resourceKey)
                return "Resource for key: " + _key; // (string)Application.Current.Resources[_key];
            else return _key;
        }
    }
 
It changes those elements to look like: Resource for key: myString. Regardless, when I put them into the TreeView they do not have a child attached
Would you like to see MultiItemString because that one works
 
7:42 PM
yeah
 
public class MultiItemString : INotifyPropertyChanged
{
private readonly string[] _keys;
private readonly MultiItemString[] _nestedItems;

private string _value;

readonly bool _resourceKey;
private readonly bool _nestedMultiItemStrings;

public MultiItemString(IEnumerable<string> keys, bool resourceKey = true)
{
_keys = keys.ToArray();
_resourceKey = resourceKey;

LanguageChange.LanguageChagned += (sender, args) => RaisePropertyChanged("");
}

public MultiItemString(IEnumerable<MultiItemString> nestedItems)
MultiItemString was created so that I could add localized strings together
StringItem is unable to do that
Sorry, forgot to format, would you like me to post it again?
 
No, it was just missing the trailing }
It shows up in my test...
 
Awesome, what did you do?
 
its the code I posted in the answer
so, nothing.
 
With the alt method?
using StringItem?
 
7:50 PM
either method
yes, using your StringItem with that modification
public string Value
{
get
{
if (_resourceKey)
return "Resource for key: " + _key; // (string)Application.Current.Resources[_key];
else return _key;
}
}
 
That doesn't make sense, why would that work?
 
did you try replacing the "(string)Application.Current.Resources[_key]" with "Resource for key: " + _key in your StringItem? As a test.
I'm thinking that maybe its not the tree that is the issue. Perhaps something else is going on?
 
Yes and this is what I get:
That's what I'm thinking too
 
huh. what does your tree xaml look like?
 
<TreeView ItemsSource="{Binding LocFuncModel.LocationDataTree.LocationTree}" SelectedItemChanged="LocFuncTreeView_SelectedItemChanged" PreviewMouseRightButtonDown="LocFuncTreeView_PreviewMouseRightButtonDown" DisplayMemberPath="DisplayName.Value"
That box is the TreeView
 
7:56 PM
<TreeView ItemsSource="{Binding TreeObservableCollection}" /> - has children
<TreeView ItemsSource="{Binding TreeObservableCollection}" DisplayMemberPath="DisplayName.Value" /> - does not have children
The XAML, I have:
<Window x:Class="WpfApplication9.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:app="clr-namespace:WpfApplication9"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<HierarchicalDataTemplate DataType="{x:Type app:TreeViewDataModel}" ItemsSource="{Binding Children}">
<TextBlock Text="{Binding DisplayName.Value}" />
</HierarchicalDataTemplate>
</Window.Resources>
<Grid>
<TreeView ItemsSource="{Binding TreeObservableCollection}" />
 
So get rid of DisplayMemberPath?
 
yeah
If you have a HierDataTemplate, it takes over
 
Boom, that was it
 
hah, sweet.
 
Ugh, thank you so much for your help
 
8:00 PM
DisplayMemberPath makes it so it doesn't use the HierDataTemplate - so no children
 
Ohh, okay, didn't know that
 
You're welcome, glad we figured it out
 
Me too. I marked your answer =)
 
I suppose that DisplayMemberPath is only good if you manually, in code, created the treeview nodes and the child nodes
Cool, thx.
I'm on fire today... +90 points
 
Nice. I might have to contact you next week, because I have more questions about TreeView children lol.
But for now, I'm headed out. Have a good weekend!
 
8:05 PM
lol, well... on Monday or Tuesday I'll be at a client's office creating a new program.
you too!
 

  last day (18 days later) »