Is there a way to declare a tuple in xaml so I can use it as a converterparameter?
Asked
Active
Viewed 5,024 times
2 Answers
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" />
-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 – Wegged Oct 12 '10 at 22:40(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 -
Interesting side note, but doesn't answer the question. – dkantowitz Aug 09 '12 at 01:58