Xaml tuple declaration

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

+7
c # tuples wpf xaml
source share
2 answers

Not directly.

There are some interesting solutions to these issues:

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

Typically, you will need to create your own type, which is not universal, and use it instead.

Example

For:

Tuple<string, int, double> 

You can create a class:

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

Then add the namespace in XAML:

 xmlns:models="clr-namespace:Models" 

Then create your instance as needed:

 <models:MyData MyString="someString" MyInt="123" MyDouble="0.1" /> 
+1
source share

You do not need to declare it in XAML. You can use x: Static to assign the ConverterParameter declared in the code:

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

And what you get should just be static:

 public static class MySettings { public static string Name { get { return "Test"; } } } 
-one
source share

All Articles