将字符串(句子)列表绑定到Label控件(到段落中,这样每个句子都是Xamarin形式的Span控件)>

问题描述 投票:0回答:1

在ViewModel中,我有一个ObservableCollection对象,其中每个对象都具有string属性。我想将此对象列表绑定到Label控件,以便每个对象的字符串属性是Span控件的Label。这有可能吗?需要帮助

示例:

型号

public class MyObject
{
    public string Sentence { get; set; }
}

public class MyViewModel
{
    public ObservableCollection<MyObject> Sentences { get; set; }
}

我需要的xaml

这是绑定后我希望得到的

<Label x:Name="LblParagraph">
    <Label.FormattedText>
        <FormattedString>
            <FormattedString.Spans>
                <Span Text="Sentence from MyObject 1"></Span>
                <Span Text="Sentence from MyObject 2"></Span>
                <Span Text="Sentence from MyObject 3"></Span>
                <Span Text="Sentence from MyObject i"></Span>
                <Span Text="Sentence from MyObject ObservableCollection.Count"></Span>
            </FormattedString.Spans>
        </FormattedString>
    </Label.FormattedText>
</Label>

如何编写我的xaml视图以获取上述xml作为结果

在我的ViewModel中,我有一个对象的ObservableCollection,其中每个对象都有一个字符串属性。我想将此对象列表绑定到Label控件,以便每个对象的字符串属性...

c# xamarin xamarin.forms xamarin.android android-databinding
1个回答
0
投票

也许我们不能直接在Xaml

© www.soinside.com 2019 - 2024. All rights reserved.