#StackBounty: #xamarin.forms How do I access a user-modified value that's embedded inside of a custom control?

Bounty: 50

How do I access a user-modified value that’s embedded inside of a custom control?

I have a custom control:

<ContentView
    x:Class="MyNamspce.LabelValuePair"
    x:Name="ParentControl"
    mc:Ignorable="d">
    <ContentView.Content>
        <StackLayout>
            ...
            <Entry Text="{Binding Source={x:Reference ParentControl}, Path=ValueText}" />
        </StackLayout>
    </ContentView.Content>
</ContentView>

Here’s how I use the custom control:

<local:LabelValuePair
    ...
    ValueText="{Binding ., Converter={StaticResource PairTemplateToEntryConverter}}" />

Here’s the backing data structure:

type LabelEntryPair2 () =

    member val LabelFGColor = "" with get,set
    member val Label        = "" with get,set
    member val EntryValue   = "" with get,set
    member val ValueFGColor = "" with get,set

I’m successful at loading values into the custom control.
However, I’m not able to retrieve the values after they are modified by the user.

Note:

The ValueText property’s setter is triggered every time I edit the entry control value thru the user interface:

The value converter, PairTemplateToEntryConverter, never invokes the ConvertBack method after I edit the entry value.

public static BindableProperty ValueTextProperty = BindableProperty.Create(
                    propertyName: "ValueText",
                    returnType: typeof(string),
                    declaringType: typeof(LabelValuePair),
                    defaultValue: "",
                    defaultBindingMode: BindingMode.TwoWay);

    public string ValueText
    {
        get { return (string)GetValue(ValueTextProperty); }
        set { SetValue(ValueTextProperty, value); } // ** This is being triggered every time **
    }

However, I’m unable to pickup these updates on the actual data structure (i.e. LabelEntryPair2)

In conclusion, How do I access a user-modified value that’s embedded inside of a custom control?


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.