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

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


Xamarin WebView based on angular for offline use

$
0
0

Hi everyone,
Can i use self-hosted server ?
What do you think ? Or someone haves other solutions ?
Thank you in advance :smile:

Xamarin forms android rendering problem in xaml preview

$
0
0

I have the following problem with the latest Visual studio 2019 for Mac. I get error for all android xaml previews
System.ArgumentException: An item with the same key has already been added. Key: Android.Support.V4.Media.Session.MediaSessionCompat+IOnActiveChangeListenerImplementor at System.Collections.Generic.Dictionary2[TKey,TValue].TryInsert (TKey key, TValue value, System.Collections.Generic.InsertionBehavior behavior) [0x002b5] in /Users/builder/jenkins/workspace/build-package-osx-mono/2019-10/external/bockbuild/builds/mono-x64/external/corefx/src/Common/src/CoreLib/System/Collections/Generic/Dictionary.cs:677
at System.Collections.Generic.Dictionary2[TKey,TValue].Add (TKey key, TValue value) [0x00000] in /Users/builder/jenkins/workspace/build-package-osx-mono/2019-10/external/bockbuild/builds/mono-x64/external/corefx/src/Common/src/CoreLib/System/Collections/Generic/Dictionary.cs:240 at Xamarin.AndroidDesigner.Java.JcwWrapperGenerator.GenerateAsync () [0x001b5] in /Users/runner/runners/2.165.0/work/1/s/Xamarin.Designer.Android/Xamarin.AndroidDesigner/Java/JcwWrapperGenerator.cs:32 at Xamarin.Designer.Tasks.WhenBoth[T1,T2] (System.Threading.Tasks.Task1[TResult] task1, System.Threading.Tasks.Task1[TResult] task2) [0x0003b] in /Users/runner/runners/2.165.0/work/1/s/Xamarin.Designer/Xamarin.Designer/TaskExtensions.cs:112 at Xamarin.AndroidDesigner.DesignerProject.SynchronizeAssemblies (System.Boolean firstSync) [0x001f1] in /Users/runner/runners/2.165.0/work/1/s/Xamarin.Designer.Android/Xamarin.AndroidDesigner/DesignerProject.cs:1814 at Xamarin.Designer.Telemetry.TimingTaskExtensions.AsTimedOperationInternal (System.Threading.Tasks.Task originalTask, System.String eventName, Xamarin.Designer.Telemetry.ITelemetryCorrelation correlation, Xamarin.Designer.Telemetry.TelemetryProperties properties, Xamarin.Designer.Telemetry.ITimingReporter reporter, System.Boolean sendToTelemetry) [0x000d5] in /Users/runner/runners/2.165.0/work/1/s/Xamarin.Designer/Xamarin.Designer/Telemetry/DesignerTelemetry.cs:240 at Xamarin.AndroidDesigner.DesignerProject.InitializeIdeProjectAsync () [0x005e4] in /Users/runner/runners/2.165.0/work/1/s/Xamarin.Designer.Android/Xamarin.AndroidDesigner/DesignerProject.cs:199 at Xamarin.AndroidDesigner.AndroidDesignerService.LoadProjectAsync (Xamarin.AndroidDesigner.IIdeProject ideProject, System.String resourcesDir, System.String projectResourcesDir) [0x00069] in /Users/runner/runners/2.165.0/work/1/s/Xamarin.Designer.Android/Xamarin.AndroidDesigner/AndroidDesignerService.cs:540 at Xamarin.AndroidDesigner.MonoDevelop.AndroidProjectWrapper.FromProjectAsync (Xamarin.AndroidDesigner.AndroidDesignerService service, MonoDevelop.Projects.Project project) [0x00097] in /Users/runner/runners/2.165.0/work/1/s/Xamarin.Designer.Android/Xamarin.AndroidDesigner.MonoDevelop/AndroidProjectWrapper.cs:102 at Xamarin.Designer.Forms.XamarinStudioXamlPreviewerView.InitializeAndroidDesignerProject (MonoDevelop.Projects.DotNetProject androidProject) [0x00030] in /Users/runner/runners/2.165.0/work/1/s/Xamarin.Designer.Forms/Xamarin.FormsPreviewer.MonoDevelop/Xamarin.Designer.Forms/XamarinStudioXamlPreviewerView.cs:575 at Xamarin.Designer.Forms.Preview.AndroidXamlRenderer.EnsureAndroidIsReady () [0x00078] in /Users/runner/runners/2.165.0/work/1/s/Xamarin.Designer.Forms/Xamarin.Designer.Forms.Preview/Android/AndroidXamlRenderer.cs:90 at Xamarin.Designer.Forms.Preview.AndroidXamlRenderer.RenderOneXaml (MonoTouch.Design.XamlRenderContext context) [0x0004b] in /Users/runner/runners/2.165.0/work/1/s/Xamarin.Designer.Forms/Xamarin.Designer.Forms.Preview/Android/AndroidXamlRenderer.cs:129 at Xamarin.Designer.Forms.Preview.AndroidXamlRenderer.RenderXamls (MonoTouch.Design.XamlRenderContext context, System.Threading.CancellationToken token) [0x003c1] in /Users/runner/runners/2.165.0/work/1/s/Xamarin.Designer.Forms/Xamarin.Designer.Forms.Preview/Android/AndroidXamlRenderer.cs:293

I have no problems with the iOS version. Does anyone know why this is displayed?

Azure Active Directory integration error The given key 'app_link' was not present in the dictionary

$
0
0

I am integrating Azure Active Directory in my Xamarin Forms project.. as of now i am testing my app for Android. After click on login button i am successfully able to launch login page of microsoft portal but when user logged in after entering their email and password i got The given key 'app_link' was not present in the dictionary exception in my app.

Please suggest any solution..

Microcharts animation

iOS "Files" app, Android ExternalStorageDirectory and saving files

$
0
0

Hello,

Trying to rephrase a question I've asked before.

I'd like to save a generated .pdf file into a common folder on a device so that a user can find those files from say email app for an attachment or just view the file external to my app.

On my iOS device, I can open Files app and browser to various folders. I noticed some apps have their own folders under "On my phone" and I can manually create a folder there too.

I'd like my app to create it's own public folder on the device and save pdf files into that. The user can then view those files by simply navigating to that folder using the Files app without needing to use my app.

Found these two links - files in iOS
and this BlogPost for Android

Can anyone else advise?
As there a plugin or sample code that'll help?

I'm expecting to write a dependency service for this on each platform.

Thanks

Is there a way of getting all the used NuGet packages in a Xamarin.Forms project from the code?

$
0
0

Title...

I need to show all of the NuGet packages used in my app in the legal info. Is there a way of doing it programmatically so that I don't have to come back each time we use a new NuGet package?

Dynamic Form data Binding to carousel view ItemSource property

$
0
0

Hello All,
I need to display dynamic forms in the carousel view. The form gets generated based on the JSON response from API and I have to show that particular form in the carousel view.

I am able to integrate my content view with some static content to the carousel view using this "CardsView(2.6.1) "package.

However, I am stuck at the data binding part because my content view is actually a dynamic form on which the data gets populated based on the JSON response from API. So, how can I create and bind the dynamic model to ItemSource Property of the carousel view?
Thanks in advance.


UWP UI Colors (Tool Bar and Tabbed Page)

$
0
0

Hello,
I feel bad that my first post here will probably be stupidly simple but I can’t seem to find this one, so after a full day of looking around I decided to ask (and accept all criticism). Created a UWP application inside an already existing (Prism) Forms project, everything referenced to the Forms nicely, but editing the colors is not straightforward at all.
Specifically the Tool Bar (or Navigation Bar?, the red square) has this gray-ish color (from the Light Theme I presume) and I can’t seem to change it or the letters. Was looking around for a non hackish solution like changing the theme’s light color, even though I haven’t tried that to even see if it works. Also the “More” dot thing (the blue circle), is redundant, there is nothing to expand, can it go away?
Lastly in the tabbed page, the icons (purple square) are stacked on the left side and I cannot seem to find anything resembling its Column Definitions, Horizontal Options or the option of whatever structure it uses to align them in the center. Do I need a custom renderer for this one?
I have no code to show, since I don’t even know from where to edit these, the Xamarin docs had an example with SolidColorBrush for buttons but since most code I found uses x:Keys to reference the items, I don’t have intellisense on those and can’t try different things out.

Thanks for any answer on any on the above in advance!

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

AppShell, changing TitleView Background Color

$
0
0

Hello,

I am trying to change the background color on an AppShell ContentPage in XAML

    <Shell.SearchHandler>
        <utils:SearchHandler Placeholder="Enter text ..." ShowsResults="True" SearchBoxVisibility="Collapsible" />
    </Shell.SearchHandler>

  <!-- Hamburger Icon Background and SearchHandler Icon Background not affected by this -->
  <Shell.TitleView>
    <StackLayout Orientation="Horizontal" HorizontalOptions="StartAndExpand" BackgroundColor="{StaticResource MyBlue}">
      <Label Text="Dashboard" FontSize ="Large" TextColor="{StaticResource MyOrange}" 
             VerticalOptions="CenterAndExpand" HorizontalOptions="StartAndExpand" />
    </StackLayout>
  </Shell.TitleView>

The Background Color and TextColor settings for the Label change as expected. But the Background Color for the Hamburger Icon and SeachHandler Magnifying Glass are unaffected.

How can I modify the TitleView to have consistent styling for all the elements?

Thanks so much.

  • Dean

Portons of Copy/Pasted XAML excluded from Preview

$
0
0

Hello,

What is the best way to include XAML snippets in forum questions? Seems that the edit control excises portions of the XAML -- at least when viewed in Preview.

Thanks.

  • Dean

Xamarin Forms - Android - ADFS 2019 integration

$
0
0

Hi Team,

In our project we have requirement of ADFS 2019 integration for SSO.

We are using Xamarin Forms targeting only Android platform.

Can you please provide if any sample is available for this. It will be great help for us.

Regards,
Thejesh.

Having different app layout parameters (sizes) by device resolution (small vs regular) ?

$
0
0

On June 28th 2019 - XamGirl wrote a devblog about splitting up resources (styling-for-multiple-device-resolutions) (I am not allowed to post direct links to the article :) )

The main concept is this about having some layout parameters in two separate Resource files "SmallDevicesStyles" and "GeneralDevicesStyles" and merging in the App constructor based on device screen resolution.

if (IsASmallDevice())
{
dictionary.MergedDictionaries.Add(SmallDevicesStyle.SharedInstance);
}
else
{
dictionary.MergedDictionaries.Add(GeneralDevicesStyle.SharedInstance);
}

I have followed the example in my solution, the runtime merge works nicely in emulators (Android/iOS), both in Debug/Release mode. When I archive the solution for publishing, the application crashes on startup (both in online emulators and real phones) complaining that the dictionary cannot find missing StaticResource keys contained in the linked file.

So my question is:

  • Is there a reason why this approach would not work in "real life" ?
  • Is there a better way to separate resources based on screen resolution ?

android:alertDialogTheme in Xamarin 4.5.0

$
0
0

Hello!

I have been using Xamarin Forms 4.2.0 for a while, and updated to 4.5.0 to use the CarouselView and IndicatorView, but when I did, my styling for the alertDialog no longer works.

I have tried to make it work, but I have been unable to.

I would appreciate any assistance on this.
Thanks!


CarouselView and ListView issues

$
0
0

Hello!

I am using a CarouselView with a ListView inside to create a kind of "quiz". The user click on the ListView object, and that object changes color(background color through binding) and the value is stored in a variable.

My issue is that when the user swipes all the way to the right in the CarouselView and back again, the ListView have been drawn again, so the color have gone back to the original color. I solved this by changing the binding as well as the object, so when it is drawn again, that object will have the correct background. But when the user now changes the answer, the old selection does not change color because I am unable to access that specific object when the user clicks.

The way I am getting the cell is by using ViewCell tapped. I have tried with ListView ItemTapped aswell, but I am still unable to access the entire list of the Listview.

So, to solve this I need to find a way to stop the CarouselView and ListView to be drawn again or be able to access the entire list of a ListView when clicking on one of the objects, and this is probably the best option, but I have been unable to find out how.

I would love some assistance in this issue.
Thanks in advance!

How to Naviagte the route from source to destination on Map?

$
0
0

Hi Everyone,
I am looking for a solution to implement the route from a source to destination in Google Map. I also want to show the progress of particle on a Map for example while traveling we enter a destination on Map and it shows the route with live tracking.
I need to implement that functionality in a map. Is it possible to achieve that in xamarin forms?

Please suggest me the way to implement it.

Thanks
Shubham

Issue on iOS with UdpClient

$
0
0

I have a small wrapper class around System.Net.Sockets.UdpClient very similar to the example in the doc. On UWP and Android this functions just fine. On iOS everything appears to work, I just get about 10% of the actual broadcast datagrams I am expecting. I have several devices on the network transmitting data every 5 seconds. So i generally get a fairly steady stream of data.

Here is my wrapper:

using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
namespace ImpactPhone.Services
{
    public delegate void ReceiveDatagram(string sourceAddress, string inboundMessage);
    public delegate void ReceiveBroadcastDatagram(string sourceAddress, string inboundMessage);
    public struct UdpState
    {
            public UdpClient UdpClient;
            public IPEndPoint EndPoint;
        }
        class UdpService
        {
            private UdpClient _udpClient;
            private IPEndPoint _endPoint;
            private int _sendPort;
            private readonly object _lockReceive = new Object();
            public event ReceiveDatagram ReceiveDatagram;
            public event ReceiveBroadcastDatagram ReceiveBroadcastDatagram;
        public async void Broadcast(string message)
            {
                    using(var client = new UdpClient())
                    {
                        client.EnableBroadcast = true;
                        var endpoint = new IPEndPoint(IPAddress.Broadcast, _sendPort);
                        var buffer = Encoding.ASCII.GetBytes(message);
                        await client.SendAsync(buffer, buffer.Length, endpoint);
                        client.Close();
                    }
            }
            public string GetIpAddress() { return _udpClient != null ? _udpClient.Client.LocalEndPoint.ToString() : string.Empty; }
            public void Initialize(int listenPort, int sendPort)
            {
                    _sendPort = sendPort;
                    _endPoint = new IPEndPoint(IPAddress.Any, listenPort);
                    _udpClient = new UdpClient(_endPoint);
                    _udpClient.EnableBroadcast = true;
                    _udpClient.BeginReceive(MessageReceived, new UdpState() {EndPoint = _endPoint, UdpClient = _udpClient});
            }
            private void MessageReceived(IAsyncResult ar)
            {
                    lock (_lockReceive)
                    {
                        UdpClient udpClient = ((UdpState) (ar.AsyncState)).UdpClient;
                        IPEndPoint ipEndPoint = ((UdpState) (ar.AsyncState)).EndPoint;
                        byte[] receiveBytes = udpClient.EndReceive(ar, ref ipEndPoint);
                        string receiveString = Encoding.ASCII.GetString(receiveBytes);
                        _udpClient.BeginReceive(MessageReceived, new UdpState() {EndPoint = _endPoint, UdpClient = _udpClient});
                        ReceiveDatagram?.Invoke(_endPoint.ToString(), receiveString);
                    }
            }
            public async Task Send(string ipAddress, string message)
            {
            using(var client = new UdpClient())
                    {
                        IPAddress destAddress = IPAddress.Parse(ipAddress);
                        var endpoint = new IPEndPoint(destAddress, _sendPort);
                        var buffer = Encoding.ASCII.GetBytes(message);
                        await client.SendAsync(buffer, buffer.Length, endpoint);
                        client.Close;
            }
        }
    }
}

And the code in the sample

    private int _messagesReceived = 0;
    public MonkeysViewModel()
    {
        source = new List<Monkey>();
        CreateMonkeyCollection();

        selectedMonkey = Monkeys.Skip(3).FirstOrDefault();
        MonkeySelectionChanged();

        SelectedMonkeys = new ObservableCollection<object>()
        {
            Monkeys[1], Monkeys[3], Monkeys[4]
        };
        _udpService.Initialize(22308,22309);
        _udpService.ReceiveBroadcastDatagram += ReceiveBroadcastDatagram;
        _udpService.ReceiveDatagram += ReceiveBroadcastDatagram;
    }
    private void ReceiveBroadcastDatagram(string source, string message)
    {
        Debug.WriteLine(message);
        _messagesReceived++;
    }

Thanks for any insights.

creating a menu on a content page

$
0
0

i would like to add a menu to the following content page:

public class MyPage: ContentPage
{
//othe vars
public MyPage()
{
Title = "My Page";
Content = new StackLayout
{
Children =
{
webView
}//children
};//content
}

// other code.....

}

I think I can build the menu by adding menu items. But I do not see how to attach to menu to this page.
How can I do this?

Error build on Iphone

$
0
0

Yesterday i update my iphone to version 13.4.1

Sinds then i have an error building to my Iphone in visualstudio for Mac ( image Catalina)

I know the free space is below the 3 gigabyte because then there is a warning , but is it the update or the free space that is to little ?

/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/iOS/Xamarin.iOS.Common.targets(3,3): Error MSB4018: The "EmbedMobileProvision" task failed unexpectedly.
System.Exception: Did not find XML plist in buffer.
  at Xamarin.MacDev.PDictionary.FromBinaryXml (System.Byte[] array) [0x0002c] in <d570b8d8ffe74cd4b8f1635c165d955d>:0 
  at Xamarin.MacDev.MobileProvision.LoadFromFile (System.String fileName) [0x0000e] in <d570b8d8ffe74cd4b8f1635c165d955d>:0 
  at Xamarin.iOS.Tasks.EmbedMobileProvisionTaskBase.Execute () [0x000eb] in <d570b8d8ffe74cd4b8f1635c165d955d>:0 
  at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute () [0x00023] in /Users/builder/jenkins/workspace/build-package-osx-mono/2019-10/external/bockbuild/builds/msbuild-15/src/Build/BackEnd/TaskExecutionHost/TaskExecutionHost.cs:574 
  at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask (Microsoft.Build.BackEnd.ITaskExecutionHost taskExecutionHost, Microsoft.Build.BackEnd.Logging.TaskLoggingContext taskLoggingContext, Microsoft.Build.BackEnd.TaskHost taskHost, Microsoft.Build.BackEnd.ItemBucket bucket, Microsoft.Build.BackEnd.TaskExecutionMode howToExecuteTask) [0x002a9] in /Users/builder/jenkins/workspace/build-package-osx-mono/2019-10/external/bockbuild/builds/msbuild-15/src/Build/BackEnd/Components/RequestBuilder/TaskBuilder.cs:814  (MSB4018) (OFB.iOS)



Viewing all 89864 articles
Browse latest View live


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