Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Declaring Tuple in Xaml

Tags:

c#

tuples

wpf

xaml

Is there a way to declare a tuple in xaml so I can use it as a converterparameter?

like image 422
Wegged Avatar asked Oct 12 '10 19:10

Wegged


1 Answers

Not directly.

There are some interesting solutions to similar questions:

  • Create a Dictionary in xaml?
  • Adding SortedList or Dictionary<int, string> to ResourceDictionary

Generally, you will have to create your own type that is non-generic and use it instead.

EXAMPLE

For:

Tuple<string, int, double>

You could create a class:

namespace Models
{
    class MyData
    {
        public MyString { get; set; }
        public MyInt { get; set; }
        public MyDouble { get; set; }
    }
}

Then add a namespace to XAML:

xmlns:models="clr-namespace:Models"

Then create your instance as needed:

<models:MyData MyString="someString" MyInt="123" MyDouble="0.1" />
like image 91
Malgaur Avatar answered Sep 24 '22 11:09

Malgaur