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

How to get sides of a centralized Expander header touchable

$
0
0

This is probably an odd question, but I need some help to get a layout working.

I have a map with a Expander sitting on top of it. The expander has a centralized "flap" image as header and a StackLayout with some other elements filling the screen horizontally as its content. The Expander itself works just fine, the problem is when it's expanded, I cannot access (tap) on the map on the sides of the "flap" but I can however when the expander is collapsed.

Here is a simplified xaml

<Grid>
  <Map />
  <Expander HorizontalOptions="Center" VerticalOptions="End">
    <Expander.Header>
      <Image HorizontalOptions="Center" ... />
    </Expander.Header>
    <Expander.Content>
      <StackLayout WidthRequest="20000"> <!-- FillAndExpand didn't work here so adding a very high width -->
           ...
      </StackLayout>
    </Expander.Content>
  </Expander>
</Grid>

In the image below, the translucid blue boxes are the areas I cannot touch the map when the Expander is open. Any ideas on how to get this layout working?


Can Design Time Data be used in conjunction with ControlTemplates

$
0
0

I have a CollectionView that is using a ControlTemplate with a custom control, can I use Design time data to display data in the XAML previewer?
The d:CollectionView.ItemSource data below is not displayed (only when I inline the ControlTemplate ...), it will only display the design time data defined in the ControlTemplate.

<CollectionView
      EmptyView="{StaticResource AdvancedEmptyView}"
      ItemSizingStrategy="MeasureFirstItem"
      ItemsSource="{Binding FilteredList}"
      SelectedItem="{Binding SelectedItem}"
      SelectionChangedCommand="{Binding SelectionChangedCommand}"
      SelectionMode="Single">
<!-- This does not display any data ... -->
    <d:CollectionView.ItemsSource>
          <x:Array Type="{x:Type models:BoText}">
            <models:BoText Name="My TestText 1" Description="Descr 1" LastDownload="09/01/2020 15:53:17" />
            <models:BoText Name="My TestText 2" Description="Descr 2" LastDownload="01/01/1800 15:53:17" />
          </x:Array>
    </d:CollectionView.ItemsSource>
      <CollectionView.ItemsLayout>
        <LinearItemsLayout ItemSpacing="10" Orientation="Vertical" />
      </CollectionView.ItemsLayout>
      <CollectionView.ItemTemplate>
        <DataTemplate>
          <ctrls:CardView
            CardDescription="{Binding Description}"
            CardPrimaryColor="AliceBlue"
            CardSecondaryColor="White"
            CardSubtitle="{Binding LastDownload, Converter={StaticResource DateConverter}, ConverterParameter='g'}"
            CardTitle="{Binding Name}"
            IconImageSource="{Binding SyncIcon}" />
        </DataTemplate>
      </CollectionView.ItemTemplate>
    </CollectionView>

<Style TargetType="ctrls:CardView">
      <Setter Property="ControlTemplate" Value="{StaticResource CardViewControlTemplate}" />
    </Style>

<ControlTemplate x:Key="CardViewControlTemplate">
      <StackLayout>
        <Frame
          x:Name="cardFrame"
          BindingContext="{Binding Source={RelativeSource TemplatedParent}}"
          BorderColor="{Binding BorderColor, FallbackValue='DarkGray'}"
          CornerRadius="10"
          HasShadow="True">
          <!--  Bind to containing Frame's BindingContext ...  -->
          <Frame.Background>
            <LinearGradientBrush StartPoint="0,0" EndPoint="1,0">
              <GradientStop Offset="0.1" Color="{Binding Source={x:Reference cardFrame}, Path=BindingContext.CardPrimaryColor}" />
              <GradientStop Offset="1.0" Color="{Binding Source={x:Reference cardFrame}, Path=BindingContext.CardSecondaryColor}" />
            </LinearGradientBrush>
          </Frame.Background>

          <Grid
            RowDefinitions="Auto, Auto, *"
            ColumnDefinitions="20,*"
            ColumnSpacing="10"
            RowSpacing="5">
            <Image
              Grid.Row="0"
              Grid.RowSpan="3"
              HeightRequest="20"
              d:Source="ic_check_circle_green_light_24dp"
              Aspect="AspectFit"
              Source="{Binding IconImageSource}" />
            <Label
              Grid.Row="0"
              Grid.Column="1"
              d:Text="Card Test Name"
              FontAttributes="Bold"
              FontSize="16"
              Text="{Binding CardTitle, TargetNullValue='TBD'}"
              TextColor="#191970" />
            <Label
              Grid.Row="1"
              Grid.Column="1"
              d:Text="21.12.2019 17:30"
              FontAttributes="Italic"
              FontSize="12"
              Text="{Binding CardSubtitle}"
              TextColor="#2F4F4F" />
            <Label
              Grid.Row="2"
              Grid.Column="1"
              d:Text="Card Test Description"
              FontSize="12"
              Text="{Binding CardDescription}" />
          </Grid>
        </Frame>
      </StackLayout>
    </ControlTemplate>

SwipeView: IsEnabled=False and GestureRecognizer

$
0
0

Inside a SwipeView I have GestureRecognizer for a single and a double tap. That works fine together. Now I want to disable the SwipeView in certain constellations. Unfortunately my GestureRecognizer is now also disabled. I just want to prevent the SwipeView to open, but there is no such property. Is there a way besides "IsEnabled=False" ? I also can not understand why it is not possible to Enable/Disable only the Left- or Right-Items, but that is another matter...

Problem with Scroll to

$
0
0

I have the code:

        var messagesPageViewModel = new MessagesPageViewModel
            {
                Id= SelectedId
            };

            var messagesPage = new MessagesPage
            {
                BindingContext = messagesPageViewModel 
            };

            await Shell.Current.Navigation.PushAsync(messagesPage );

MessagesPageViewModel:

       public string Id
        {
            get { return _id; }
            set
            {
                SetProperty(ref _id, value);
                InitMessages();
            }
        }

 private void InitMessages()
        {
            ...............

            MessagingCenter.Send(this, "ScrollTo", Messages.LastOrDefault());
        }

the scroll to does not work, the problem is that it is called before the page is loaded with the data in the ui:

 private async void InitMessages()
        {
            ...............

        await Task.Delay(10);
            MessagingCenter.Send(this, "ScrollTo", Messages.LastOrDefault());
        }

this works, but it seems like a good solution, any alternative?

how to draw over the captured image by camera

$
0
0

Hi,

I want to draw freehand drawing on captured image by camera in my application 1st i captured the image and captured images is previewed on that image i have to draw freehand drawing over it.

i also got some solution to solve this issue i.e.use of skiasharp nuget package and create the empty canvas image and draw on it.but this solution not helped me to solve my issue.

please help me to how to draw freehand drawing on captured image.

Thank you in advance

Not able to reference Xamarin.Essentials in .Android project

$
0
0

I have added Xamarin.Essentials to all the projects. But when I try to put in the setup code in ManiActivity's OnCreate event, Xamarin.Essentials is not referenced. It is not in the References too. Unable to add it separately. The NuGet explorer shows that it is installed for Android project too.

My Android project is targeted to V8.1 and Android Support Libraries are of V27.0.2.1 as required by the documentation.

What am I missing?

Unable to build iOS. ie "The application has not been built"

$
0
0

Hi,

I'm in VS for Mac version 8.7.3(build 13), recently i'm facing 2 issues.
1. Neither on simulator nor on device i can build iOS app. it says "This application has not been built".
2. Break point wont work on android.

Looking for some help.

Thanks..!

Getting Plugin.GoogleClient.Shared.GoogleClientBaseException in android project

$
0
0

I am trying to add GoogleLogin in the application but getting this error

{Plugin.GoogleClient.Shared.GoogleClientBaseException: 10:
at Plugin.GoogleClient.GoogleClientManager.LoginAsync () [0x000cb] in <83ed24c9c5a7433abaaefc1fcc35c1f0>:0
at PlugAndPlay.ViewModel.MainPageViewModel.LoginGoogleAsync (PlugAndPlay.AuthNetwork authNetwork) [0x000ed] in F:\Apps\PlugAndPlay\PlugAndPlay\ViewModel\MainPageViewModel.cs:182 }

Here is the code-->

try
            {
             if (!string.IsNullOrEmpty(_googleService.AccessToken))
             {
                //Always require user authentication
                   _googleService.Logout();
               }

              EventHandler<GoogleClientResultEventArgs<GoogleUser>> userLoginDelegate = null;
             userLoginDelegate = async (object sender, GoogleClientResultEventArgs<GoogleUser> e) =>
             {
                    switch (e.Status)
                    {
                        case GoogleActionStatus.Completed:

if DEBUG

                           var googleUserString = JsonConvert.SerializeObject(e.Data);
                           Debug.WriteLine($"Google Logged in succesfully: {googleUserString}");

endif

                           var socialLoginData = new NetworkAuthData
                           {
                              Id = e.Data.Id,
                             Logo = authNetwork.Icon,
                             Foreground = authNetwork.Foreground,
                             Background = authNetwork.Background,
                                Picture = e.Data.Picture.AbsoluteUri,
                                Name = e.Data.Name,
                          };

                           await App.Current.MainPage.Navigation.PushModalAsync(new HomePage(socialLoginData));
                           break;
                       case GoogleActionStatus.Canceled:
                          await App.Current.MainPage.DisplayAlert("Google Auth", "Canceled", "Ok");
                         break;
                     case GoogleActionStatus.Error:
                           await App.Current.MainPage.DisplayAlert("Google Auth", "Error", "Ok");
                           break;
                    case GoogleActionStatus.Unauthorized:
                              await App.Current.MainPage.DisplayAlert("Google Auth", "Unauthorized", "Ok");
                          break;
                  }

                       _googleService.OnLogin -= userLoginDelegate;
               };

              _googleService.OnLogin += userLoginDelegate;

              await _googleService.LoginAsync();
          }
          catch (Exception ex)
          {
             Debug.WriteLine(ex.ToString());
          }

I don't know what is wrong with this code.

Any Help?


Validate input using validation properties from the database ( min, max, etc... )

$
0
0

I'm trying to implement input validation in survey's input fields. The surveys are built at runtime, feeding from the database, so static validation, like DataAnnotations, won't do. I tried using the .net System.Web.UI.WebControls validators on the Web Service (SOAP) the app is connected to, but realised half way through, that those cannot validate values directly, and must be assigned to UI controls. Seems like the only solution is to implement my own validation system.

Before I do that, I wanted to ask if there's a simpler solution, that I'm simply not aware of. Is there a library that already does that in Xamarin or Net? Or maybe there's a way to override built-in validators, so that they would accept direct value? It is a very 'shot in the dark' question for a very specific case, for which I apologise, but I think it's better to ask, than blindly go the hard way.

Many thanks

CollectionView change default selected color

$
0
0

Hi, How can i do the custom render for a collection view selected cell like did for a listview ?

Switch button tint color

$
0
0

Hi
If Switch is inside StackLayout with black background, then the background of switch (tint) is not visible.
Can someone show how to change or control that color. Have a look at attached for clarification.
Thank you.

How do you clear selection in CollectionView in multiselect mode?

$
0
0

The ObservableCollection has a list of items with the first item called 'Any', the plan is to clear the other selected items when 'Any' is selected and clear 'Any' when other items are selected.
How would such a feature be implemented?
The code below is utilizing MVVMHelpers.

ViewModel

public class SimpleViewModel : BaseViewModel
{
public ObservableCollection<FilterType> FilterOptions { get; private set; }
        public ObservableCollection<object> SelectedOptions
        {
            get => selectedOptions;
            set {  SetProperty(ref selectedOptions, value);  }
        }

public string SelectionList
        {
            get => _selectionList;
            set  {  _selectionList = value;
                OnPropertyChanged("SelectionList");
            }
        }

public SimpleViewModel()
        {
            FilterOptions = new ObservableCollection<Widget>();

             FilterOptions.Add(new Widget() { Name = "Any" });
            FilterOptions.Add(new Widget() { Name = "Wilma" });
            FilterOptions.Add(new Widget() { Name = "Barney" });
            FilterOptions.Add(new Widget() { Name = "Betty" });
            FilterOptions.Add(new Widget() { Name = "Pebbles" });
            FilterOptions.Add(new Widget() { Name = "Bambam" });

            SelectedOptions = new ObservableCollection<object>();

            // Add collection changed handler
            SelectedOptions.CollectionChanged += SelectedOptions_CollectionChanged;

            UpdateSelectionList();
        }

private void SelectedOptions_CollectionChanged(object sender, 
                                               System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {  }

        void UpdateSelectionList()
        {
            SelectionList = String.Join(", ", SelectedOptions.Cast<Widget>().Select(t => t.Name));
        }
}

XAML

     <StackLayout>
            <StackLayout Orientation="Horizontal" HorizontalOptions="Center">
                <Label Text="Selected : " FontAttributes="Bold" />
                <Label Text="{Binding SelectionList}" />
            </StackLayout>
            <CollectionView x:Name="collectionView" ItemsSource="{Binding FilterOptions, Mode=OneWay}" 
                                           SelectionMode="Multiple"
                            SelectedItems="{Binding SelectedOptions, Mode=TwoWay}">
                <CollectionView.ItemTemplate>
                    <DataTemplate>
                        <Grid Padding="10">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>                           
                            <Label Grid.Column="0"
                               Text="{Binding Name, Mode=OneTime}" />
                        </Grid>
                    </DataTemplate>
                </CollectionView.ItemTemplate>
            </CollectionView>
        </StackLayout>

An example

CollectionView not deselecting

$
0
0

Hi everyone. I decided to try re-implement one of my apps with Xamarin.Forms, and the experience so far has been awesome. However, I have been trying to deselect all items on my CollectionView by setting SelectedItems to null through a property in the ViewModel. This has networked out and I can't find any solution anywhere. I am running on the latest stable version of Xamarin.Forms.

Help would be greatly appreciated🙏!

CollectionView, Long press and Tap!

Is it possible to detect a long tap on a CollectionView item?

$
0
0

I started using the new CollectionView, but I can't figure out how to detect a long tap (and execute a command) on an item in the CollectionView.
So far I've been using the Syncfusion SfListView which comes with a HoldCommand, but i'd like to start using the CollectionView and I need to have that same feature.

Thanks in advance if someone can provide a simple example.


ListView with Activity Indicator

$
0
0

Hello, Attached screen shot will help you understand the scenario, I have a welcome page having "Place Order" button and Order Page, on clicking Place Order button order page will be loaded by using given code:

Navigation.PushAsync(new Order());

I am populating ListView on Order form load by using given code:

public Order()
    {
        this.InitializeComponent();
        GetSupplierItem();
        orderDetails = new List<OrderDetail>();

        NavigationPage.SetTitleView(this, new Image()
        {
            Source = "MatlobaMiqdar.png"
        });
        NavigationPage.SetHasBackButton(this, false);
    }


public void GetSupplierItem()
    {
        Mainlistview.ItemsSource = Baqala.ServiceHandler.GetSupplierItemForOrderBySupplierID(1);
}

I want to show the loading animation till the listview loaded, to achieve this I have used ActivityIndicator but it does not worked, I tried a lot, here is my .xaml code:

<?xml version="1.0" encoding="utf-8" ?>

<ContentPage.Content>

    <StackLayout Padding="4" BackgroundColor="#f0f0f0" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand">

        <ActivityIndicator x:Name="activity" Color="YellowGreen" IsRunning="{Binding IsBusy}" IsVisible="{Binding IsBusy}"   />

        <ListView  x:Name="Mainlistview"  RowHeight="74" HasUnevenRows="True" SeparatorColor="YellowGreen" SelectionMode="None" ItemTapped="Mainlistview_ItemTapped" >


            <ListView.ItemTemplate>
                <DataTemplate>

                    <ViewCell>



                        <StackLayout  Orientation="Horizontal" Margin="2,2,2,4" Spacing="1" >


                            <StackLayout Padding="2">
                                <Image x:Name="ItemPicture" Source="{Binding Item.ItemPicture, StringFormat='http://baqala-pk.com/Images/Vegetableimages/{0}'}" WidthRequest="70" HeightRequest="70"  />
                            </StackLayout>

                            <StackLayout Orientation="Vertical" VerticalOptions="StartAndExpand" HorizontalOptions="StartAndExpand" Padding="0" Margin="4,0,0,0">

                                <Label x:Name="ItemName" Text="{Binding Item.ItemName}" TextColor="Orange" LineBreakMode="NoWrap"  />
                                <Label x:Name="Price" Text="{Binding Price, StringFormat='RS.{0}/KG'}" HorizontalOptions="StartAndExpand" TextColor="#503026" FontFamily="calbiri"  LineBreakMode="NoWrap" />


                            </StackLayout>






                            <StackLayout WidthRequest="130" Padding="0" HorizontalOptions="EndAndExpand"  Margin="0,0,6,0">

                                <Grid  HorizontalOptions="EndAndExpand" WidthRequest="120" HeightRequest="70" Padding="0,0,0,0" Margin="0,0,0,0" RowSpacing="0">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*" />
                                    </Grid.ColumnDefinitions>
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="22" />
                                        <RowDefinition Height="*" />
                                    </Grid.RowDefinitions>


                                    <Frame Grid.Row="0" Grid.Column="0" CornerRadius="5" Padding="0" BackgroundColor="Gray" HorizontalOptions="End" WidthRequest="64" Margin="1">
                                        <Label  x:Name="ItemName2" Grid.Row="0" Grid.Column="0" Text="Rs.0" TextColor="White" FontSize="11" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" />
                                    </Frame>



                                    <Frame Grid.Row="1" Grid.Column="0" CornerRadius="6" Padding="0" BackgroundColor="LightGray" HorizontalOptions="End" WidthRequest="160">
                                        <StackLayout WidthRequest="160" HeightRequest="22" Orientation="Horizontal" Padding="0" Margin="0" HorizontalOptions="End" >

                                            <Button x:Name="DeductQty" Text="-" Clicked="OnClicked_DeductQty" CommandParameter="{Binding .}" Padding="0" Margin="0" BorderColor="YellowGreen" HorizontalOptions="End" HeightRequest="20" WidthRequest="24" IsEnabled="False" TextColor="White" Font="Bold, 20" />
                                            <Entry x:Name="Qty2" WidthRequest="60" HeightRequest="14" Text="0" FontSize="Small" MaxLength="2" Margin="0" HorizontalOptions="Center" InputTransparent="True" TextColor="Black" ></Entry>
                                            <Button x:Name="AddQty" Text="+"  Clicked="OnClicked_AddQty" CommandParameter="{Binding .}" Padding="0" Margin="0" BorderColor="YellowGreen" HorizontalOptions="Start" HeightRequest="20" WidthRequest="24" BackgroundColor="YellowGreen" TextColor="White" Font="Bold, 20" />


                                        </StackLayout>
                                    </Frame>
                                </Grid>
                            </StackLayout>
                        </StackLayout>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

        <Frame FlowDirection="MatchParent" CornerRadius="5" Margin="2" Padding="4" BackgroundColor="#d3d3d3" HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" WidthRequest="400" >
            <StackLayout Orientation="Vertical" HorizontalOptions="Center" VerticalOptions="Center">
                <StackLayout Orientation="Horizontal" HorizontalOptions="Center" VerticalOptions="Center" >
                    <Label x:Name="lblOrderTotal1" Font="Bold, 14" TextColor="Red" Text="Total: Rs." />
                    <Label x:Name="lblOrderTotal" Font="Bold, 14" TextColor="Red" Text="0.00" />
                </StackLayout>
                <Button x:Name="butPlaceOrder" Margin="0,2,0,0" Clicked="OnClicked_butPlaceOrder" HeightRequest="30" WidthRequest="160" FontSize="14" TextColor="White" BackgroundColor="Orange" Padding="0" CornerRadius="15"  Text="Continue" IsVisible="False" />
            </StackLayout>
        </Frame>
    </StackLayout>

</ContentPage.Content>


Load Image to a Mediafile varidabel using its address image path

$
0
0

Using media plugin we can get and store image to mediafile like this

private MediaFile _mediafile;  
_mediaFile = await CrossMedia.Current.PickPhotoAsync(new PickMediaOptions
        { 
        });

New the problem is How to get and load image to a mediafile using image path

private MediaFile _mediafile;  
_mediaFile =  "Image path from the device"

Stylise the page title text

$
0
0

Hi

Xamarin Forms 4.8. VS 2019 16.7.0.

I am trying to stylise the page title text such as font size and alignment using NavigationPage.TitleView. I am using below code for my page but its not working. This is the result when page is running;

What am I missing?

Thanks

Regards

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:d="http://xamarin.com/schemas/2014/forms/design"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             mc:Ignorable="d"
             Title="This text shows"             
             Shell.TabBarIsVisible="False"
             x:Class="StaffApp.Views.MainPage">

    <NavigationPage.TitleView>
        <Label Text="This text does not show" FontSize="15" FontAttributes="None" HorizontalTextAlignment="Center" />
    </NavigationPage.TitleView>

    <ContentPage.Content>
        <StackLayout>
            <Label Text="Welcome to App Home Page"
                VerticalOptions="CenterAndExpand" 
                HorizontalOptions="CenterAndExpand" />
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

How do I send an email using Xamarin.Essentials with an attachment from a memory file?

$
0
0

The subject line says it all really: how do I send an email using Xamarin.Essentials.EmailMessage with an attachment from a memory file?

I found this code on SO that does it for 'normal' .NET: [https://stackoverflow.com/questions/5336239/attach-a-file-from-memorystream-to-a-mailmessage-in-c-sharp](Email File From MemoryStream). But I am not sure how to map this onto the Xamarin.Essentials.EmailMessage class because of the way the Mime type is constructed.

Can anyone offer any advice or suggestions?

Incidentally, the file I am attaching is for the foreseeable future (famous last words) text-only. So a solution or workaround that works for text would be great!

Kind wishes - Patrick

ListView/CollectionView is not filling the entire Screen on some iOS devices

$
0
0

In some iOS devices, the Listview or CollectionView is not filling the entire screen. without changing anything in the code, it behaves correct on other devices.

We had one scenario where in one iPhone XR its working perfect but in other iPhone XR device with same configuration its not showing as expected. Please find the sample code below.

Please help us in fixing the issue.

Viewing all 79144 articles
Browse latest View live


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