开发者

Declaring Tuple in Xaml

Is there a way to declare a tuple in xaml so I can u开发者_C百科se it as a converterparameter?


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" />


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"; }
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜