Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

Custom control with content

$
0
0

Hello developers,

I have this control:

        public static readonly BindableProperty TitleProperty = BindableProperty.Create(nameof(Title), typeof(string), typeof(FrameView), default(string));
        public static readonly BindableProperty CardContentProperty = BindableProperty.Create(nameof(CardContent), typeof(View), typeof(FrameView), default(View));
        public static readonly BindableProperty CommandProperty = BindableProperty.Create(nameof(Command), typeof(ICommand), typeof(ItemView), default(ICommand));
        public static readonly BindableProperty CommandParameterProperty = BindableProperty.Create(nameof(CommandParameter), typeof(object), typeof(ItemView), default(object));

        public string Title
        {
            get => (string)GetValue(TitleProperty);
            set => SetValue(TitleProperty, value);
        }

        public View CardContent
        {
            get => (View)GetValue(CardContentProperty);
            set => SetValue(CardContentProperty, value);
        }

        public ICommand Command
        {
            get => (ICommand)GetValue(CommandProperty);
            set => SetValue(CommandProperty, value);
        }

        public object CommandParameter
        {
            get => GetValue(CommandParameterProperty);
            set => SetValue(CommandParameterProperty, value);
        }

        public FrameView()
        {
            InitializeComponent();
            Content.BindingContext = this;
        }

and

        <ContentView xmlns="http://xamarin.com/schemas/2014/forms" 
                     xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                     x:Class="App1.Views.Templates.FrameView">
            <ContentView.Content>
                <Frame Style="{StaticResource frameGeneral}">
                    <StackLayout Spacing="0">
                        <Label Style="{StaticResource labelFrameView}" Text="{Binding Title}"/>
                        <BoxView HeightRequest="1" Color="Gray"/>
                        <!--CONTENT-->
                        <ContentPresenter Content="{Binding CardContent}" />
                        <!--END CONTENT-->
                        <StackLayout.GestureRecognizers>
                            <TapGestureRecognizer Command="{Binding Command}" CommandParameter="{Binding CommandParameter}" />
                        </StackLayout.GestureRecognizers>
                    </StackLayout>
                </Frame>
            </ContentView.Content>
        </ContentView>

Then I use:

            <views:FrameView Title="Contact" Command="{Binding SendEmailCommand}">
                <views:FrameView.CardContent>
                    <StackLayout Padding="16">
                        <Label Style="{StaticResource labelGeneral}">
                            <Label.FormattedText>
                                <FormattedString>
                            <Span Text="For any problem "/>
                                <Span Text="click here " FontAttributes="Bold" >
                                    <Span.GestureRecognizers>
                                        <TapGestureRecognizer Command="{Binding OpenTermsCommand}" />
                                    </Span.GestureRecognizers>
                                </Span>
                                </FormattedString>
                            </Label.FormattedText>
                        </Label>
                    </StackLayout>
                </views:FrameView.CardContent>
            </views:FrameView>

The problem is that TapGestureRecognizer of the Span not work, all else it works!

I think it has to do with the context, but I need the command of the content to be defined in the ViewModel and not in the control

any idea?


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>