Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how use List<T> within xaml?

So I am pretty sure that up in the definition part I need to include something along the lines of:

xmlns:s="clr-namespace:System.Collections.Generic;assembly=?????" 

but I just do not know what to put in place of the ???'s.

What I want to do with the code is this:

<UserControl.DataContext>
    <ObjectDataProvider 
          MethodName="CreateNodes"
          ObjectType="{x:Type local:TreeViewModel}" >
        <ObjectDataProvider.MethodParameters>
            <s:List<T>>
                  {Binding Nodes}
            </s:List<T>>
        </ObjectDataProvider.MethodParameters>
    </ObjectDataProvider>
</UserControl.DataContext>

So that when I make the objectDataProvider call, I can pass the list in to the method that it is calling (CreateNodes)...

How do I go about doing this?

thanks!

Edit - could be a fix?

I just put this in the method, instead of passing in the list, it is just an app variable...I dont know if app variables are bad though

  List<TNode> existingNodes;

  if (Application.Current.Properties.Contains("ExistingNodes")) existingNodes = Application.Current.Properties["ExistingNodes"] as List<TNode>;
  else existingNodes = new List<TNode>();
like image 797
Toadums Avatar asked Oct 11 '22 04:10

Toadums


1 Answers

The assembly part of the XML namespace declaration would be mscorlib.

But anyway, XAML doesn't support generics (*), so you can't do it. Instead, you could create a class that inherits List<T> and use it in XAML:

class ListOfFoo : List<Foo>
{
}

(1) Actually generics are supported in XAML 2009, but most of XAML 2009 is not supported in compiled XAML. See this question for more information.

like image 108
Thomas Levesque Avatar answered Oct 14 '22 04:10

Thomas Levesque