Hello,
I think the problem with contentview (view)
Yes, you cannot use BindableProperty
to transfer view to the contentview, before you bind value to the Label in the CollectionView, this view was set to the contentview, so you this value of label cannot be show.
You can change the <ContentView x:Name="expandContent" Content="{Binding Source={x:Reference this},Path=HeaderContent}" WidthRequest="270"/>
to <Label x:Name="expandContent" WidthRequest="270"/>
in the ExpansionPanel.xaml
.
Then open your ExpansionPanel.xaml.cs
to change the type of HeaderContentProperty
to string
and set the Label value in the HeaderContentChanged
method like following code.
By the way, do not forget to change type of expandContent = (Label)GetTemplateChild("expandContent");
to Label
public static readonly BindableProperty HeaderContentProperty = BindableProperty.Create(
propertyName: nameof(HeaderContent),
returnType: typeof(string),
declaringType: typeof(ExpansionPanel),
null,
propertyChanged:HeaderContentChanged
);
static void HeaderContentChanged(BindableObject bindable, object oldValue, object newValue)
{
expandContent.Text = newValue as string;
}
public string HeaderContent
{
get => (string)GetValue(HeaderContentProperty);
set => SetValue(HeaderContentProperty, value);
}
private static Label angleIcon; // access the icon control.
private static Label expandContent; // access the icon control.
protected override void OnApplyTemplate()
{
base.OnApplyTemplate();
angleIcon = (Label)GetTemplateChild("angleIcon");
expandContent = (Label)GetTemplateChild("expandContent");
}
Next, open your <CollectionView >
, change c:ExpansionPanel
like following code
<c:ExpansionPanel HeaderContent="{Binding Header,Converter={StaticResource langConverter}}">
<Label Text="{Binding Details,Converter={StaticResource langConverter}}"/>
</c:ExpansionPanel>
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.