Bind a textblock to static property which isn'

2019-09-02 04:25发布

This is my xaml code:

<TextBlock Text="{Binding MyTranslations[0].Name}"></TextBlock>

What I want to do is remove the 0. Instead of 0, I need to get the correct integer from a static field in a static class which is in another project but in the samo solution.

I guess it should look like something like this:

<TextBlock Text="{Binding MyTranslations[MyStaticClass.MyStaticInt].Name}"></TextBlock>

How do I do this?

1条回答
三岁会撩人
2楼-- · 2019-09-02 05:19

There is probably some strange way to do this syntactically in xaml, but usually when I come across strange problems like this, I usually just make a calculated property in my VM.

public string MyCurrentTranslation
{
    get { return MyTranslations[MyStaticClass.MyStaticInt].Name; }
}

Then just bind to that property:

<TextBlock Text="{Binding MyCurrentTranslation}"/>
查看更多
登录 后发表回答