【发布时间】:2019-05-07 01:03:03
【问题描述】:
这是我现在需要做的一个例子。有时我有一个跨度,有时更多。
请注意,此帖子与另一个问题的帖子相似。对于另一个问题,我只有一条评论来使用自定义控件,没有提供更多建议,并且有一个使用 JavaScript 的答案。我试图为该问题添加第二个赏金,但它让我可以选择仅添加 500 分的赏金。这个问题现在太老了,我怀疑有人会再看到它,而且因为我不能添加赏金(除非它是 500 分),所以我不能给它更多的可见性。
以下是我想简化的内容:
<Label>
<Label.FormattedText>
<FormattedString>
<Span Text="Hello " />
<Span Text="Hello " />
<Span Text=" Some more text." />
</FormattedString>
</Label.FormattedText>
</Label>
这是我想要做的,而不是输入<Label><Label.FormattedText><FormattedString> 我想通过只输入<template:FormattedLabel> 获得一些方法来做到这一点
<template:FormattedLabel>
<Span Text="Hello " />
<Span Text="Hello " />
<Span Text=" Some more text." />
</template:FormattedLabel>
或
<template:FormattedLabel>
<Span Text="Hello " />
</template:FormattedLabel>
请注意,我已经研究了自定义控件,但据我所知,我无法找到一种方法让这些控件接受一些内部内容,在这种情况下,这些内容将是一个或多个跨度。
我有一个类似的例子,也许可以使用,但我不知道如何应用它。我希望在下面的 XAML 中有一个这样的模板,它的功能与我需要的类似,但用于内容页面:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Japanese;assembly=J"
xmlns:t="clr-namespace:J.Templates"
x:Class="Japanese.Templates.ContentScrollable"
x:Name="ContentPage" >
<ContentPage.Content>
<t:Stack Orientation="Vertical">
<ScrollView x:Name="scroll">
<ContentView Content="{Binding Source={x:Reference ContentPage}, Path=InnerContent}"
Margin="{DynamicResource PageMargin}" />
</ScrollView>
</t:Stack>
</ContentPage.Content>
</ContentPage>
使用其 C# 后端:
public partial class ContentScrollable : ContentPage
{
public static readonly BindableProperty InnerContentProperty = BindableProperty.Create(nameof(InnerContent), typeof(View), typeof(ContentScrollable));
public View InnerContent
{
get => (View)this.GetValue(InnerContentProperty);
set => this.SetValue(InnerContentProperty, value);
}
public ContentScrollable()
{
InitializeComponent();
}
}
我怎样才能完成我正在寻找的东西?
【问题讨论】:
-
你的截图链接失效了
-
您好,我没有截图链接。像这样的话只是指后面的文字。我会改变它以使用一些不同的词。感谢您指出。
-
这适用于实现 ContentView 的东西,但我认为在这种情况下它没有帮助。
-
你刚才不是问过这样的问题吗?然后我将您定向到UserControl for cross-platform Xamarin Forms,为什么不符合您的要求?
标签: xamarin xamarin.forms