Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all 79144 articles
Browse latest View live

WebView is not loading URL in UWP

$
0
0

Hello,

I have a simple project in which I load a URL on a WebView. It is working as expected on Android, but on UWP, the WebView doesn't load anything and keep in blank.

It's not a problem of Width/Height as I have changed the background color and I can check it. Furthermore, I tried with a sample project of the docs, and it isn't working too. I don't know what's happening and I can't see nothing in the Output.

I'm using the latest version of Visual Studio 2019 and Xamarin.Forms. Already checked 'Internet Client & Server' Capabilities on UWP properties.

Someone knows what could I do to solve this?


Exception while navigating from App.xaml.cs with Prism and DryLoc (RELEASE ONLY)

$
0
0

Hello,

When I try to run my application in release mode, it only shows a white screen when deployed. I've managed to trace the code from the logs, and I've found that the first navigation is throwing an exception:

**Message: ** Unable to get constructor of Test.Views.LoginPage using provided constructor selector when resolving Test.Views.LoginPage: Object {ServiceKey="LoginPage"} FactoryId=52 IsResolutionCall from Container without Scope
with Rules with {AutoConcreteTypeResolution} and without {UseFastExpressionCompilerIfPlatformSupported}
with Made={FactoryMethod=ConstructorWithResolvableArguments}.

**Stacktrace: **

at DryIoc.Throw.For[T] (System.Boolean throwCondition, System.Int32 error, System.Object arg0, System.Object arg1, System.Object arg2, System.Object arg3) [0x00020] in <0a86de686e464708b60aa6773e19d33b>:0 at DryIoc.ReflectionFactory.CreateExpressionOrDefault (DryIoc.Request request) [0x00066] in <0a86de686e464708b60aa6773e19d33b>:0 at DryIoc.Factory.GetExpressionOrDefault (DryIoc.Request request) [0x0012e] in <0a86de686e464708b60aa6773e19d33b>:0 at DryIoc.Container.DryIoc.IResolver.Resolve (System.Type serviceType, System.Object serviceKey, DryIoc.IfUnresolved ifUnresolved, System.Type requiredServiceType, DryIoc.Request preResolveParent, System.Object[] args) [0x001a2] in <0a86de686e464708b60aa6773e19d33b>:0 at DryIoc.Resolver.Resolve (DryIoc.IResolver resolver, System.Type serviceType, System.Object serviceKey, DryIoc.IfUnresolved ifUnresolved, System.Type requiredServiceType, System.Object[] args) [0x00000] in <0a86de686e464708b60aa6773e19d33b>:0 at Prism.DryIoc.DryIocContainerExtension.Resolve (System.Type type, System.String name) [0x00006] in <5fe086bb7e8d47c3a9f1c36dce9746ea>:0 at Prism.Ioc.IContainerProviderExtensions.Resolve[T] (Prism.Ioc.IContainerProvider provider, System.String name) [0x00000] in <aadb680bd8e9478189f606fd633a4198>:0 at Prism.Navigation.PageNavigationService.CreatePage (System.String segmentName) [0x00000] in <fe20bbc2e107492eb7c7e45796362bb2>:0

With debug mode, it is working properly. And it isn't a XAML problem as I tried to use an Empty page for navigating.

Xamarin Forms v4.7.0.1080
Prism.Dryloc.Forms v7.2.0.1422

The linking options for release mode are Sdk And User assemblies, and none for debug

Do you have an idea of what could be happening? Or how could I trace deeply to find out which is the problem maybe?

WebView controls not working / how to implement scroll and tap

$
0
0

am using web view to display html text on my application. I need the user to be able to scroll and tap the text. However That seems to be close to impossible. TapGesture is just not firing and based on my search its not mistake on my side but seems that since webview its usually used to display web pages and they include buttons to no need for tap gesture. So if i use my custom control it work however i cant scroll the content and if i use scroll around the webview then it doenst work as needed. Once i implemented the custom control i can see then action in my output however the content doesnt move.

public class ExtendedWebView : WebView
{
public ExtendedWebView()
{
}

    public event EventHandler Touched;

    public void OnTouched() =>
    Touched?.Invoke(this, null);
    public ICommand PannedCommand
    {
        set { SetValue(PannedCommandProperty, value); }
        get { return (ICommand)GetValue(PannedCommandProperty); }
    }
    public static readonly BindableProperty PannedCommandProperty = BindableProperty.Create(nameof(PannedCommand), typeof(ICommand), typeof(ExtendedWebView));
}

[assembly: ExportRenderer(typeof(ExtendedWebView), typeof(ExtendedWebViewRenderer))]
namespace AVAT.Droid.Renderers
{
public class ExtendedWebViewRenderer : WebViewRenderer
{
public static int _webViewHeight;
static ExtendedWebView _xwebView = null;
public WebView _webView;
bool isScroll;
public ExtendedWebViewRenderer(Context context) : base(context)
{

    }

    class ExtendedWebViewClient : WebViewClient
    {
        WebView _webView;
        public async override void OnPageFinished(WebView view, string url)
        {
            try
            {
                _webView = view;
                if (_xwebView != null)
                {

                    view.Settings.JavaScriptEnabled = true;
                    await Task.Delay(100);
                    string result = await _xwebView.EvaluateJavaScriptAsync("(function(){return document.body.scrollHeight;})()");
                    _xwebView.HeightRequest = Convert.ToDouble(result);


                }
                base.OnPageFinished(view, url);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"{ex.Message}");
            }
        }
        public override bool ShouldOverrideUrlLoading(Android.Webkit.WebView view, IWebResourceRequest request)
        {
            return true;
        }
    }

    protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.WebView> e)
    {
        base.OnElementChanged(e);
        _xwebView = e.NewElement as ExtendedWebView;
        _webView = Control;

        if (e.OldElement == null)
        {
            _webView.SetWebViewClient(new ExtendedWebViewClient());
        }
        _webView.Touch += (object sender, TouchEventArgs eventArgs) =>
        {

            if (eventArgs.Event.Action == Android.Views.MotionEventActions.Down)
            {
                var webview = Element as ExtendedWebView;

                webview.OnTouched();
            }
        };
        _webView.Touch += _webView_Touch;

        void _webView_Touch(object sender, TouchEventArgs e)
        {
            var webview = Element as ExtendedWebView;
            bool isMove = true;
            Console.WriteLine(e.Event.Action);
            switch (e.Event.Action)
            {
                case Android.Views.MotionEventActions.Down:

                    isScroll = true;
                    break;
                case Android.Views.MotionEventActions.Move:
                    isScroll = true;
                    if (isMove)
                    {
                        isMove = false;
                        webview.PannedCommand?.Execute(null);
                    }
                    break;
                case Android.Views.MotionEventActions.Up:

                    if (!isScroll)
                    {
                        webview.OnTouched();
                    }
                    break;
                default:
                    break;
            }
        }
    }
}

}


Maybe you guys have experience how to implement both controls tap and scroll?

Scrollview is not working when applied for listview with itemselected function

$
0
0

Hello Sir,
Scrollview is not working when applied for listview with itemselected function.Please help Thanks
Below is the code.

 <ScrollView Orientation="Both">
    <StackLayout Padding="10">
        <Label Text="User Details!" />
    <Button  Text="Add New User " Clicked="Button_Clicked" />

        <ListView x:Name="Models" Header="" ItemSelected="Models_ItemSelected" >
            <ListView.HeaderTemplate>
                <DataTemplate>
                    <Grid >

                        <Grid.RowDefinitions>
                            <RowDefinition Height="20" />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="50" />
                            <ColumnDefinition Width="100" />
                            <ColumnDefinition Width="100" />
                            <ColumnDefinition Width="100" />
                            <ColumnDefinition Width="350" />
                        </Grid.ColumnDefinitions>
                        <Label Grid.Column="0"  Text="Id" TextColor="Blue" />
                        <Label Grid.Column="1"  Text="Role" TextColor="Blue" />
                        <Label Grid.Column="2"  Text="Username"  TextColor="Blue"/>
                        <Label Grid.Column="3" Text="Password" TextColor="Blue" />
                        <Label Grid.Column="4"  Text="Email" TextColor="Blue" />
                </Grid>

            </DataTemplate>
            </ListView.HeaderTemplate>

            <ListView.ItemTemplate>
                <DataTemplate>

                    <ViewCell>
                        <Grid  HorizontalOptions="CenterAndExpand">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="100" />
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="50" />
                                <ColumnDefinition Width="100" />
                                <ColumnDefinition Width="100" />
                                <ColumnDefinition Width="100" />
                                <ColumnDefinition Width="350" />

                            </Grid.ColumnDefinitions>
                            <Label Grid.Column="0" Text="{Binding userId}" />
                            <Label Grid.Column="1" Text="{Binding rolename}" />
                            <Label Grid.Column="2" Text="{Binding username}" />
                            <Label Grid.Column="3" Text="{Binding password}" />
                            <Label Grid.Column="4" Text="{Binding email}" />
                        </Grid>
                </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>

        </ListView>

    <StackLayout VerticalOptions="CenterAndExpand" Padding="5" IsVisible="false" x:Name="update_user">
        <StackLayout Orientation="Horizontal">
            <Entry Text="" x:Name="userid" IsReadOnly="True" HorizontalOptions="FillAndExpand" Placeholder="Please enter userid" FontSize="Small"/>
            <Entry Text="" x:Name="name" HorizontalOptions="FillAndExpand" Placeholder="Please enter name" FontSize="Small" />
        </StackLayout>
        <StackLayout Orientation="Horizontal">
            <Entry Text="" x:Name="username" IsReadOnly="True" HorizontalOptions="FillAndExpand"  FontSize="Small"/>
            <Entry Text="" x:Name="username_new"  HorizontalOptions="FillAndExpand" Placeholder="Please enter new username" FontSize="Small"/>
        </StackLayout>
        <StackLayout Orientation="Horizontal">
            <Entry Text="" x:Name="password" IsReadOnly="True" HorizontalOptions="FillAndExpand"  FontSize="Small"/>
            <Entry Text="" x:Name="password_new"  HorizontalOptions="FillAndExpand" Placeholder="Please enter new password" FontSize="Small"/>
        </StackLayout>
        <StackLayout Orientation="Horizontal">
            <Entry Text="" x:Name="email" HorizontalOptions="FillAndExpand" Placeholder="Please enter email" FontSize="Small"/>
            <Entry Text="" x:Name="designation" HorizontalOptions="FillAndExpand" Placeholder="Please enter designation" FontSize="Small"/>
        </StackLayout>
        <Button Text="Update" x:Name="update" Clicked="update_Clicked" ></Button>

    </StackLayout>
</StackLayout>
</ScrollView>

INSTALL_FAILED_INVALID_APK: Failed to extract native libraries, res=-2

$
0
0

Hi!

After upgrading to Version 8.7 (build 2037)
I can't distribute my Android APK, it works fine when running on Release-mode thru VS to device but when building APK and trying to install I get
"INSTALL_FAILED_INVALID_APK: Failed to extract native libraries, res=-2"

Anybody experienced anythings similar ?

Info (16393) / Finsky: [10916] dda.a(14): Decompressing com.mobisma.Truckify (com.mobisma.Truckify) format 1 Info (16393) / Finsky: [11152] his.run(25): Stored data usage stats for package com.mobisma.Truckify; completed bytes: 21096891. Info (16393) / Finsky: [10916] dda.a(21): com.mobisma.Truckify (com.mobisma.Truckify) (58955507 bytes) copied successfully in 2381 ms Info (16393) / Finsky: [2] ntd.run(14): IT: Removed com.mobisma.Truckify from ResourceManager for copy success. Info (16393) / Finsky: [2] ntf.a(7): IT: Successfully copied APK to update com.mobisma.Truckify (adid: com.mobisma.Truckify , isid: _Z6lTNC_TnuH2_mkbYOVow) Info (16393) / Finsky: [2] nua.b(9): IT: com.mobisma.Truckify to state 40 Info (16393) / Finsky: [10923] nrh.accept(22): IT: starting next download: package=com.mobisma.Truckify Info (16393) / Finsky: [10923] nqz.a(3): Handling streamingComplete for com.mobisma.Truckify gid: 0 Info (16393) / Finsky: [10923] nua.c(56): IT: Begin install of com.mobisma.Truckify (isid: _Z6lTNC_TnuH2_mkbYOVow) Info (16393) / Finsky: [10923] nra.a(188): Installer: Notifying status update. package=com.mobisma.Truckify, status=INSTALLING Info (16393) / Finsky: [10962] odj.b(52): IQ: Notifying installation update. package=com.mobisma.Truckify, status=INSTALLING Info (16393) / Finsky: [2] hub.a(11): Selecting account [g2cNcEkt4qyAHQHQHBj4L4nIXedQdYObSnt3w1p78X4] for package com.mobisma.Truckify. overriding=[true] Info (16393) / Finsky: [2] hub.a(11): Selecting account [g2cNcEkt4qyAHQHQHBj4L4nIXedQdYObSnt3w1p78X4] for package com.mobisma.Truckify. overriding=[true] Info (16393) / Finsky: [2] hub.a(11): Selecting account [g2cNcEkt4qyAHQHQHBj4L4nIXedQdYObSnt3w1p78X4] for package com.mobisma.Truckify. overriding=[true] Info (16393) / Finsky: [2] hub.a(11): Selecting account [g2cNcEkt4qyAHQHQHBj4L4nIXedQdYObSnt3w1p78X4] for package com.mobisma.Truckify. overriding=[true] Info (25196) / Finsky:download_service: [11448] juk.a(20): onRemove(request_id=334, files_to_download=1, group_id=com.mobisma.Truckify, display_data[invisible=false, title=Truckify], network_restrictions=4, status=succeeded, bytes_downloaded=21096891, retry[count=0, next_retry=n/a]) Error (16393) / Finsky: [2] tyc.onReceive(17): Error -504 while installing com.mobisma.Truckify: INSTALL_FAILED_INVALID_APK: Failed to extract native libraries, res=-2 Warning (16393) / Finsky: [2] ntx.a(17): IT: Install failure of com.mobisma.Truckify (isid: _Z6lTNC_TnuH2_mkbYOVow): -504, Exception: n/a Warning (16393) / Finsky: [2] nua.a(192): IT: Cleanup running installation of com.mobisma.Truckify (com.mobisma.Truckify) Info (16393) / Finsky: [10909] nrz.run(12): IT: Running resource fetching of com.mobisma.Truckify canceled. Info (16393) / Finsky: [2] nra.b(32): Installer: stopping tracking of task: com.mobisma.Truckify Info (16393) / Finsky: [2] nra.a(188): Installer: Notifying status update. package=com.mobisma.Truckify, status=INSTALL_ERROR Info (16393) / Finsky: [10962] odj.b(52): IQ: Notifying installation update. package=com.mobisma.Truckify, status=INSTALL_ERROR Info (16393) / Finsky: [2] hub.a(11): Selecting account [g2cNcEkt4qyAHQHQHBj4L4nIXedQdYObSnt3w1p78X4] for package com.mobisma.Truckify. overriding=[true] Info (16393) / Finsky: [2] hub.a(11): Selecting account [g2cNcEkt4qyAHQHQHBj4L4nIXedQdYObSnt3w1p78X4] for package com.mobisma.Truckify. overriding=[true] Info (16393) / Finsky: [2] hub.a(11): Selecting account [g2cNcEkt4qyAHQHQHBj4L4nIXedQdYObSnt3w1p78X4] for package com.mobisma.Truckify. overriding=[true] Info (16393) / Finsky: [2] hub.a(11): Selecting account [g2cNcEkt4qyAHQHQHBj4L4nIXedQdYObSnt3w1p78X4] for package com.mobisma.Truckify. overriding=[true]



Getting error like The requested resource does not support http method 'POST'. in Web Api

$
0
0

Hello Sir, Im trying to update the status of 2 tables using web api but getting below error The requested resource does not support http method 'POST'. Please help me Thanks in advance.
Below is the web api code

 public Response UpdateUserDeTails(useraccounts userdetails)
    {
        Response response = new Response();
        try
        {
            SqlCommand cmd = new SqlCommand("update table1 t1 join table2 t2 on t1.userId = t2.userId set t1.status = " + 0 + ", t2.status = " + 0 + " where t1.userId = @userId", con);
            cmd.Parameters.AddWithValue("@userId", userdetails.userId);
            con.Open();
            int i = cmd.ExecuteNonQuery();
            con.Close();
            if (i >= 1)
            {
                response.Message = "User details deleted successfully";
                response.Status = 1;
            }
            else
            {
                response.Message = "Failed to save";
                response.Status = 0;
            }
        }
        catch (Exception ex)
        {
            response.Message = ex.Message;
            response.Status = 0;

        }
        return response;
    }

CollectionView's implementation as StaggeredGridLayout problem?

$
0
0

I'm implementing CollectionView as a StaggeredGridLayout and write a custom renderer for it on android as:

[assembly: ExportRenderer(typeof(CollectionView), typeof(CustomCollectionViewRenderer))]
namespace App.Droid
{
public class CustomCollectionViewRenderer : CollectionViewRenderer
{
public CustomCollectionViewRenderer(Context context) : base(context)
{
}

    protected override void OnElementChanged(ElementChangedEventArgs<ItemsView> elementChangedEvent)
    {
        base.OnElementChanged(elementChangedEvent);

        if (elementChangedEvent.NewElement != null)
        {
            StaggeredGridLayoutManager manager = new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.Vertical);
            SetLayoutManager(manager);
        }
    }
}

}

It's working fine at the start of the application when initialized, but when i try to update or add more items, the item source of collectionview does not accept any data and becomes empty. It only populate the data template of collectionview at initialization but not after updating.

At initialization :

After updating item source:

  • I have tried by binding it to viewModel and also by directly setting its item source

pinterest app like collection of images in Xamarin Forms

$
0
0

Can someone suggest me a solution to implement xamarin forms collectionview like in this picture with variable size of heights and same spacing in each column and pictures without top alignment of each row.

Or any solution other than collectionview to implement such layout


How do I 'move' the clipping rectangle on a SkiaSharp SKCanvas?

$
0
0

I think I am missing a trick with SkiaSharp. It's difficult to explain without diagrams but here goes...

Imagine I have a single canvas that I conceptually want to divide into three columns. Now imagine I want to draw different shapes into each of the three columns but I want the shapes to clip at the column boundaries. And finally I want to draw a shape that extends over the whole canvas.

I can change the clipping rectangle to draw in the first column. When it comes to drawing in the second, how do I do this? If I call ClipRect() again, the second rectangle is combined with the first (either subtracted or intersected). What I want to do is clear the first clip rectangle I set, or somehow reset the clipping rectangle to be the whole canvas.

And when it comes to drawing my final shapes that fill the whole canvas, I definitely need to put the clipping rectangle back to being the whole canvas.

How would I do this?

Kind wishes - Patrick

Intercept page leaving event

$
0
0

Basically I would like to ask the user, if he really wants to move away from the current page. How would I do that? I have a MasterDetailPage. Is there an event like the disappearing but before the page gets destroyed?

Video Compression in Xamarin PCL

$
0
0

Hi,

Can any one help me on video compression without using ffmpeg as this is not working from Android Nougat version. Please share sample code. Any help is appreciated..!! Thank you.

Xamarin Forms Video Compression

$
0
0

hi,

is there any cross platform plugins available for video compression ?

any help will be appreciated.

Video Compression in Xamarin

$
0
0

I'm looking for video compression in Xamarin Forms. I am using plugin.media to take video then I upload that video to server but video size is too big. I need to compress video but there is no specific solution. I need to implement platform specific solution but I couldn't find any solution platform specific on Android and iOS. Is there any solution for video compression on Android and iOS.

How to make label (or other custom views based on layout) focusable and support TabIndex

$
0
0

How to make label (or other custom views based on layout) focusable and support TabIndex
Mainly for UWP keyboard navigation and "ReturnType=Next" navigation as well.

One possible question is how to make label text bold when a label is focused?

<StackLayout IsTabStop="True" TabIndex="7" Focused="StackLayout_Focused">

    <Entry Text="Entry0" TabIndex="0" IsTabStop="True" ReturnType="Next"></Entry>
    <Label Text="lable1" TabIndex="1" IsTabStop="True" Focused="Label_Focused" AutomationProperties.IsInAccessibleTree="True" TextColor="Black"></Label>
    <Entry Text="Entry2" TabIndex="2" IsTabStop="True" ReturnType="Next"></Entry>
    <Label Text="lable3" TabIndex="3" IsTabStop="True"  Focused="Label_Focused" AutomationProperties.IsInAccessibleTree="True" TextColor="Black"></Label>
    <Entry Text="Entry4" TabIndex="4" IsTabStop="True" ReturnType="Next"></Entry>
    <Label Text="lable5" TabIndex="5" IsTabStop="True"  Focused="Label_Focused" AutomationProperties.IsInAccessibleTree="True" TextColor="Black"></Label>
    <Label Text="lable6" TabIndex="6" IsTabStop="True"  Focused="Label_Focused" AutomationProperties.IsInAccessibleTree="True" TextColor="Black"></Label>

</StackLayout>




    private void Label_Focused(object sender, FocusEventArgs e)
    {
        ((Label)sender).FontAttributes = FontAttributes.Bold;
    }

Just for info
https://stackoverflow.com/questions/54949444/xamarin-layout-cant-receive-focus
https://github.com/xamarin/Xamarin.Forms/issues/9999
https://github.com/xamarin/Xamarin.Forms/issues/7568

Masonry view in Xamarin forms

$
0
0

i started Xamarin Forms a month ago and i am trying to implement sample Ui (attached) For android and iOS using list view and grid view with some nested views to show image and labels

So idea is i will have list view with grid . And grid will have two columns and two rows . if image is portrait grid child row span will be 1 and grid child column span will be 2 . I am new to Xamarin Forms so i am confused that is there any event that will trigger when ever a view cell is added and can pass me view cell with Access to grid in that view cell so i can change to span values of grid child ?

any help in the code to get started will be help full


Masonry list style in Xamarin

$
0
0

I need to list the announcements on a content page just like masonry style (https://halcyon-theme.tumblr.com/) but I couldn't be successful on it. My problem is that the Scrollview doesn't cover whole the page when I use the Parent Stacklayout's Vertical alignment option set as FillAndExpand. But if I set the Scrollview and Parent StackLayout as static height value, It's okay but due to per item's height will change, I can't use it that's the way as you guess.

 <StackLayout x:Name="stckParent" Orientation="Vertical" VerticalOptions="FillAndExpand">
                    <Grid VerticalOptions="FillAndExpand" RowSpacing="0" ColumnSpacing="0">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="auto"/>
                        </Grid.RowDefinitions>

                        <StackLayout x:Name="stckLeft" Grid.Column="0" Margin="0,0,2,0"
                                  Orientation="Vertical" VerticalOptions="FillAndExpand">
                        </StackLayout>

                        <StackLayout x:Name="stckRight" Grid.Column="1" Margin="2,0,0,0"
                                  Orientation="Vertical" VerticalOptions="FillAndExpand">
                        </StackLayout>

                    </Grid>
                </StackLayout>

</ScrollView>


public MainPage()
        {
            InitializeComponent();

            var list = new ObservableCollection<Announcement>
            {
                new Announcement
                {
                    ID = 1,
                    Title = "Yedek parça siparişlerinizde %22' ye varan indirim!",
                    ImagePath = "https://image5.sahibinden.com/photos/08/54/18/x5_719085418j7p.jpg",
                    IsActive = true,
                    CreateDate = DateTime.Now,
                },
                new Announcement
                {
                    ID = 2,
                    Title = "Fren Balataları Hangi Sıklıkla Değiştirilmelidir?",
                    ImagePath = "https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcTJzQfduSrJ3Nh7SHzGSGrCmTnWses4AcfuRSnU7hX4y9XN4TSU&usqp=CAU",
                    IsActive = true,
                    CreateDate = DateTime.Now,
                }
            };

            DeviceHelper helper = DependencyService.Get<IDeviceHelper>().GetDevice();

            double height = 0;

            for (int m = 0; m < 6; m++)
            {
                for (int i = 0; i < list.Count; i++)
                {

                    Frame frame = new Frame
                    {
                        Padding = new Thickness(0, 0, 0, 0)
                    };

                    // Stack
                    StackLayout stack = new StackLayout
                    {
                        Margin = new Thickness(10),
                    };

                    // Image
                    Image image = new Image
                    {
                        Source = list[i].ImagePath,
                        HorizontalOptions = LayoutOptions.FillAndExpand,
                        VerticalOptions = LayoutOptions.FillAndExpand
                    };

                    // Title
                    Label title = new Label
                    {
                        Text = list[i].Title,
                        Margin = new Thickness(0, 6, 0, 0),
                        FontSize = 13
                    };

                    // Date
                    Label date = new Label
                    {
                        Text = list[i].CreateDate.ToString().Substring(0, 10), // temporary workaround
                        Margin = new Thickness(0, 6, 0, 0),
                        TextColor = Color.Gray,
                        FontSize = 11
                    };

                    stack.Children.Add(image);
                    stack.Children.Add(title);
                    stack.Children.Add(date);

                    frame.Content = stack;


                    if (i % 2 == 0)
                    {
                        stckLeft.Children.Add(frame);
                    }
                    else
                    {
                        stckRight.Children.Add(frame);

                        SizeRequest columnSizeRequest = frame.Measure(600, 800);
                        height += columnSizeRequest.Request.Height * 6; // *6 is estimated height, what should be the solution?
                    }
                }
            }
            stckLeft.HeightRequest = height;
            stckRight.HeightRequest = height;

            scrList.HeightRequest = helper.ScreenHeight - 100;

        }

Why Scrolview doesn't fill the whole page?
What is the best practice to able to do the masonry-style page?

How can I obtain a frame size that just bound? {
SizeRequest columnSizeRequest = frame.Measure(300, 400); // the result is always 41, It's not make sense..
height += columnSizeRequest.Request.Height * 6;

}

except for estimated height value, not bad :)

GitHub link; https://github.com/Erdogan34/Test-Masonry

thanks

Picker - SelectedItem Binding on pageload

$
0
0

Hi Guys,

Need your help pls as tested this alot and still couldn't find why my picker can't select the related item on the page load.
Note : All Categories are loaded in picker but the issue is that I can't see the related category selected.

Your helps are highly appreciated.

*My VM:

private ObservableCollection _AllCats;
public ObservableCollection AllCats
{
set
{
this._AllCats = value;
OnPropertyChanged();
}
get
{
return this._AllCats;
}
}

    private Category _SelectedCat;
    public Category SelectedCat
    {           
       set
        {
            this._SelectedCat = value;
            OnPropertyChanged();
        }
        get
        {
            return this._SelectedCat;
        }
    }

    public ProdsMngtDetailViewModel(Product product , Category selectedcat)
    {
        GetCatsAsync();
        SelectedCat = selectedcat;
        SelectedProduct = product;
        CategoriesService cs = new CategoriesService();
        AllCats = cs.GetAllCats2();
    }

private async void GetCatsAsync()
{
CategoriesService cs = new CategoriesService();
List list = await cs.GetCategoriesAsync();
AllCats = new ObservableCollection(list);
}

XAML:

VS2019 the specified path file name or both are too long error !

$
0
0

Hi everyone !

I'm archiving to publish ios from my Xamarin forms project, but I get an error ;

I've put my project on a shorter path to fix this error. (In :C). But , I keep getting errors. Because I think archive files are being created in a very different place. I couldn't solve this problem. How do I move the archive files? Ultimately these files in AppData. Wouldn't it be a mistake to relocate them?

My project location

My project archive location

What should I do. Please help me !

Path too long Xamarin iOS Distribute

$
0
0

Help me pls i can't distribute because my paths are too long.
I tried to change them but it didn't help.
I'm really out of ideas.
That's the error:
Unable to copy file "C:\Users\cunnin\AppData\Local\Xamarin\MonoTouch\Archives\2019-10-18\ZAsetMobile.iOS 10-18-19 10.22 AM.xcarchive\mSYMs\ZAsetMobile.iOS.app.mSYM\b5883af4fb74101e3ffa838fae7f2094\Microsoft.Extensions.DependencyInjection.Abstractions.dll.msym" to "obj\iPhone\AppStore\archives\ZAsetMobile.iOS 10-18-19 10.22 AM.xcarchive\mSYMs\ZAsetMobile.iOS.app.mSYM\b5883af4fb74101e3ffa838fae7f2094\Microsoft.Extensions.DependencyInjection.Abstractions.dll.msym". The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.

I don't finds a way to change the path in xamarin settings.

[Skiasharp] How to get consistent canvas scale across multiple aspect ratios?

$
0
0

I'm currently developing a cloth editor for a friend's tailor shop using skiasharp. I wanted to use the ClipPath to prevent users from placing images or text outside of the bounds of the cloth that is being edited or some other effects. The problem is that I haven't been able to consistently align the path with the cloth design across different devices with different aspect ratios. Here are some images to show better the problem and below the code I'm currently using:

Samsung Galaxy J2 Pro - 540 x 960 pixels, 16:9 ratio (~220 ppi density)

While it is not perfect, the result is very acceptable.

Samsung Galaxy A20s - 720 x 1560 pixels, 19.5:9 ratio (~264 ppi density)

But in this case the clip path is completely not aligned with the bitmaps of the shirt

Here is the code for the Paint Surfce event:

void SKCanvasView_PaintSurface_Post(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info = args.Info;
            SKSurface surface = args.Surface;
            SKCanvas canvas = surface.Canvas;

            canvas.Clear();
            canvas.SetMatrix(matrix);

            if (AreBitmapsLoaded) //Make sure that bitmaps that are being loaded in a different thread are ready.
            {
                if (IsManipulating) //This draws a copy of the bitmap if it can be manipulated so it can be seen even if outside the clip path
                {
                    foreach (TouchManipulationBitmap manipulationBitmap in Bitmaps)
                    {
                        if (manipulationBitmap.Interactable && current == manipulationBitmap)
                        {
                            manipulationBitmap.Paint(canvas, info.Width, info.Height, painto);
                            break;
                        }
                    }
                }

                //Cliping canvas to path
                if (!CalculateClippingOnce)
                {
                    TestPath.GetTightBounds(out bounds);
                    TranslateCanvasX = info.Width / 2f;
                    TranslateCanvasY = info.Height / 2f;

                    ratio = bounds.Width >= bounds.Height
                    ? info.Height / bounds.Height
                    : info.Width / bounds.Width;

                    CalculateClippingOnce = true;
                }

                canvas.Translate(TranslateCanvasX, TranslateCanvasY);
                canvas.Scale(0.85f * ratio);
                canvas.Translate(-bounds.MidX, -bounds.MidY);
                canvas.ClipPath(TestPath, SKClipOperation.Intersect, true);
                canvas.ResetMatrix();

                Bitmaps = Bitmaps.OrderBy(b => b.ZOrder).ToList(); //A questionable way of having a Z order.

                foreach (TouchManipulationBitmap manipulationBitmap in Bitmaps)
                {
                    manipulationBitmap.Paint(canvas, info.Width, info.Height);
                }

                if (current == null)
                {
                    current = Bitmaps[0];
                }
            }


            if (TakeAndSaveSnapshot)
            {
                TakeAndSaveSnapshot = false;

                SKPixmap pixmap = surface.PeekPixels();

                Render = new SKBitmap();
                Render.InstallPixels(pixmap);

                Task.Run(async () =>
                {
                    await ProcessDesign();
                });
            }
        }

I think it will be useful to share the code for the Paint function in the TouchManipulationBitmap class:

public void Paint(SKCanvas canvas, int infoWidth, int infoHeight, SKPaint paint = null)
        {
            canvas.Save();
            SKMatrix matrix = Matrix;
            canvas.Concat(ref matrix);

            if (ShouldColor) // The shadow details in the shirt should not be colored for example.
            {
                if (TargetColor == null)
                {
                    TargetColor = SKColors.White;
                }

                paint = new SKPaint();

                var tableRed = new byte[256];
                var tableGreen = new byte[256];
                var tableBlue = new byte[256];

                for (int i = 0; i < 256; i++)
                {
                    tableRed[i] = TargetColor.Red;
                    tableGreen[i] = TargetColor.Green;
                    tableBlue[i] = TargetColor.Blue;
                }

                paint.ColorFilter = SKColorFilter.CreateTable(null, tableRed, tableGreen, tableBlue);
                paint.FilterQuality = SKFilterQuality.Low;
            }

            if (!IsText) // if the bitmap does not represent text.
            {
                if (!CalculateDrawOnce)
                {
                    float scale = Math.Min((float)infoWidth / bitmap.Width, (float)infoHeight / bitmap.Height);
                    float x = (infoWidth - scale * bitmap.Width) / 2;
                    float y = (infoHeight - scale * bitmap.Height) / 2;

                    rect = new SKRect(x, y, x + scale * bitmap.Width, y + scale * bitmap.Height);

                    Scale = scale;
                    X = x;
                    Y = y;

                    CalculateDrawOnce = true;
                }

        canvas.DrawBitmap(bitmap, rect, paint);
            }
            else
            {
                float x = (infoWidth -  bitmap.Width) / 2;
                float y = (infoHeight - bitmap.Height) / 2;

                X = x;
                Y = y;

                canvas.DrawBitmap(bitmap, x, y, paint);
            }

            canvas.Restore();
        }

Some other useful Information:

-> The shirt is a mix of bitmaps that are being draw one on top of the other and they align perfectly just as I designed in Figma.
-> The TestPath fits perfectly the contour of the bitmaps when made in Figma, but won't align once I try inside the app.
-> The reason there are foreach loops it's because the user can upload their own images to make a design, or add text or change the cloth type (let's say a short) so the bitmaps to be draw are not fixed. I feel it is probably not the best approach and while it is not the main focus of my question, if you have any feedback on this I would love to listen to it.

This is my first attempt at coding anything with Skiasharp so my code is a mix of tutorials I found around and changes I made to fulfill the needs of the app, so any guidance on how to solve my problem will be nice, Thanks!

Viewing all 79144 articles
Browse latest View live


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