9

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

Wegged
  • 2,383
  • 20
  • 26

2 Answers2

1

Not directly.

There are some interesting solutions to similar questions:

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" />
Community
  • 1
  • 1
Malgaur
  • 1,842
  • 15
  • 17
-1

You don't need to declare it in XAML. You can use x:Static to assign a ConverterParameter declared in code:

<TextBlock Text="{Binding Converter={x:Static local:MyConverter.Default}, ConverterParameter={x:Static local:MySettings.Name}}" />

And what you're accessing just needs to be static:

public static class MySettings
{
    public static string Name
    {
        get { return "Test"; }
    }
}
John Bowen
  • 24,213
  • 4
  • 58
  • 56
  • I am aware I dont need to in fact I have this already Tuple visibleTuple = new Tuple(Visibility.Collapsed, Visibility.Visible); this.Resources.Add("visibleTuple", visibleTuple); just thought there had to be a way to do it in xaml with all the new features in xaml2009 – Wegged Oct 12 '10 at 22:40
  • Interesting side note, but doesn't answer the question. – dkantowitz Aug 09 '12 at 01:58