Xamarin.forms 如何添加“;查看更多信息”;并在3行后的标签末尾查看较少的内容
我的标签中有10行数据,但只需要显示3行,然后需要添加更多视图按钮和扩展更少视图,如何以xamarin形式添加它根据您的描述,您可以使用自定义控件来完成此操作 首先,您需要创建contentview,名称为LargeTextLabel.xamlXamarin.forms 如何添加“;查看更多信息”;并在3行后的标签末尾查看较少的内容,xamarin.forms,Xamarin.forms,我的标签中有10行数据,但只需要显示3行,然后需要添加更多视图按钮和扩展更少视图,如何以xamarin形式添加它根据您的描述,您可以使用自定义控件来完成此操作 首先,您需要创建contentview,名称为LargeTextLabel.xaml <ContentView.Content> <StackLayout Orientation="Vertical"> <Label x:Name="SmallLabel"
<ContentView.Content>
<StackLayout Orientation="Vertical">
<Label
x:Name="SmallLabel"
BackgroundColor="Beige"
HeightRequest="50"
IsVisible="true" />
<Label
x:Name="FullLabel"
BackgroundColor="BurlyWood"
HeightRequest="200"
IsVisible="false" />
<Button x:Name="ExpandContractButton" Text="See More" />
</StackLayout>
</ContentView.Content>
现在,您可以在页面中使用此自定义控件
<ContentPage.Content>
<StackLayout>
<local:LargeTextLabel
Command="{Binding ExpandContractCommand}"
Expanded="{Binding TextExpanded}"
Text="{Binding LabelText}" />
</StackLayout>
</ContentPage.Content>
键入local:LargeTextLabel not found。我这样添加了xmlns:local=“clr namespace:ProjectName”@Mayuri,我已经在github上传了示例,请下载并尝试测试它。如果我的回复解决了您的问题,请记住将我的回复标记为答案,谢谢。嗨,这对我不起作用,我有一个列表视图,其中消息是它们的,如果消息标签超过5行,我想添加更多。否则我不想显示更多按钮当前,每个标签上都添加了更多按钮,并且无法单击到exampland@Cherry Bu-MSFT
<ContentPage.Content>
<StackLayout>
<local:LargeTextLabel
Command="{Binding ExpandContractCommand}"
Expanded="{Binding TextExpanded}"
Text="{Binding LabelText}" />
</StackLayout>
</ContentPage.Content>
public partial class Page3 : ContentPage, INotifyPropertyChanged
{
private string _LabelText;
public string LabelText
{
get { return _LabelText; }
set
{
_LabelText = value;
RaisePropertyChanged("LabelText");
}
}
private ICommand _ExpandContractCommand;
private bool _TextExpanded;
public bool TextExpanded
{
get { return _TextExpanded; }
set
{
_TextExpanded = value;
RaisePropertyChanged("TextExpanded");
}
}
public Page3 ()
{
InitializeComponent ();
LabelText = "Can any one help me on this?\nI want set read more option for multiline text end of label when i click on that read more it will expand or navigate to the any other page. Please help me on this .\n\nThanks in advance.";
this.BindingContext = this;
}
public ICommand ExpandContractCommand
{
get
{
if (_ExpandContractCommand == null)
{
_ExpandContractCommand = new Command(() => {
TextExpanded = !TextExpanded;
});
}
return _ExpandContractCommand;
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void RaisePropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
}