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

List with templated controls, all with mvvm bindings

$
0
0

Hello, my problem is that i want to have the list on UI that is bound to observable collection in page's view model and that observable collection has controls' view models inside. I want items in this list to be customized so i cant use ViewCells i guess.

Here is my code (full code available at github (cant post proper links) /ProtonSoftware/Timeinator/tree/Development/Patryk):

Page's view model:
public ObservableCollection TaskItems { get; set; } = new ObservableCollection();

Page's xaml:

        <local:ItemsControl.ItemTemplate>
            <DataTemplate>
                <local:TimeTaskControl />
            </DataTemplate>
        </local:ItemsControl.ItemTemplate>

    </local:ItemsControl>

Control's xaml:

<local:ContentControl.Resources>

    <ResourceDictionary>
        <ControlTemplate x:Key="ContentTemplate">

            <Frame>

                <StackLayout Orientation="Vertical">

                    <Label Text="{Binding Name}" />

                </StackLayout>

            </Frame>

        </ControlTemplate>
    </ResourceDictionary>

</local:ContentControl.Resources>

<local:ContentControl ControlTemplate="{StaticResource ContentTemplate}" />

Both "ItemsControl" and "ContentControl" are downloaded from microsoft's github as a substitute for the same controls that exist in WPF. (I tried with Listview and ContentView but it didnt work).

Now the problem is that - list is bound properly, if i have 3 vms in collection it displays 3 controls BUT these controls are empty and BindingContext of every control is null, even though collection is a list of view models that are proper for the control. How to fix that?


How to make tabs on bottom of the page?

$
0
0

I am looking for tabs which will be on the bottom part of the page. I tried the xamarin forms TabbedPage, but for ios only the tabs are coming bottom and for android and windows the tabs are showing on the top. Is there any way to achieve this feature?

size of app with crossplatform and xamarin.androif

$
0
0
when get apk file from crossplatform is size of this is bigger than when creat xamarin.android not crossplatform


And for ios ,too

List with template controls mvvm bindings

$
0
0

Hello, my problem is that i want to have the list on UI that is bound to observable collection in page's view model and that observable collection has controls' view models inside. I want items in this list to be customized so i cant use ViewCells i guess.

Here is my code (full code available at github (cant post proper links) /ProtonSoftware/Timeinator/tree/Development/Patryk):

Page's view model:
public ObservableCollection TaskItems { get; set; } = new ObservableCollection();

Page's xaml:

<local:ItemsControl ItemsSource="{Binding TaskItems}">

    <local:ItemsControl.ItemTemplate>
        <DataTemplate>
            <local:TimeTaskControl />
        </DataTemplate>
    </local:ItemsControl.ItemTemplate>

</local:ItemsControl>

Control's xaml:

<local:ContentControl.Resources>

<ResourceDictionary>
    <ControlTemplate x:Key="ContentTemplate">

        <Frame>

            <StackLayout Orientation="Vertical">

                <Label Text="{Binding Name}" />

            </StackLayout>

        </Frame>

    </ControlTemplate>
</ResourceDictionary>

</local:ContentControl.Resources>


Both "ItemsControl" and "ContentControl" are downloaded from microsoft's github as a substitute for the same controls that exist in WPF. (I tried with Listview and ContentView but it didnt work).

Now the problem is that - list is bound properly, if i have 3 vms in collection it displays 3 controls BUT these controls are empty and BindingContext of every control is null, even though collection is a list of view models that are proper for the control. How to fix that?

Scrolling multiple list view together

$
0
0

Hi all,
I've a carousel page, each page has the same structure with a listView. My question is:
is it possibile to scroll the different listViews in different pages together?

List View Didn't load correctly

$
0
0

i'm using ...
VS 2017 version 15.8.6 ;
Xamarin.Forms 3.3.0.871608
syncfusionListView ...


when we load sfListview ... we had to set height manually
if we don't ... its a fill more than height of parent and items didn't apear


screen shots


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

<ContentPage.Content>


<Grid.RowDefinitions>


</Grid.RowDefinitions>

            <StackLayout Grid.Row="1" Padding="20" Spacing="10" VerticalOptions="StartAndExpand" HorizontalOptions="FillAndExpand">

                <Controls:CustomLabel TextColor="#660000" Text="{Binding ValidationMessage}" IsVisible="{Binding HasErrors}"
                                      HorizontalOptions="FillAndExpand"
                                          HorizontalTextAlignment="Center" 
                                       LineBreakMode="CharacterWrap" MaxLines="50"/>

                <StackLayout>
                    <Controls:CustomLabel x:Name="lbRemoveAll" Text="{Resx:TranslateExtension Text=lbSetCartEmpty}"  Style="{StaticResource lbLinkButton}">
                        <Controls:CustomLabel.GestureRecognizers>
                            <TapGestureRecognizer Tapped="RmoveAllItems_Tapped"/>
                        </Controls:CustomLabel.GestureRecognizers>
                    </Controls:CustomLabel>

                </StackLayout>

                <StackLayout>
                    <sfListView:SfListView 
                        Grid.Row="1"
                        x:Name="lvItems"
                        AllowSwiping="True"
                        ItemsSource="{Binding TbCartItems}"
                        SelectionBackgroundColor="Transparent"
                        ItemSpacing="10"
                        AutoFitMode="Height"
                        LoadMoreOption="None"
                        IsScrollBarVisible="False"
                        FlowDirection="LeftToRight"
                        Orientation="Vertical"
                        ItemSize="100" >

                        <sfListView:SfListView.ItemTemplate>
                            <DataTemplate>
                                <Frame HasShadow="True" BackgroundColor="White" Padding="5"
                                  FlowDirection="{Binding Source={x:Static Helpers:Settings.dFlowdirection}}">

                                    <Controls:CustomLabel Text="Ahmad Azim"/>


                                </Frame>
                            </DataTemplate>
                        </sfListView:SfListView.ItemTemplate>
                    </sfListView:SfListView>

                </StackLayout>

                <StackLayout x:Name="slTotal">
                    <Controls:CustomLabel   Text="{Resx:TranslateExtension Text=lbItemsTotal}" HorizontalTextAlignment="Center"/>
                    <Controls:CustomLabel   Text="{Binding Total}" HorizontalTextAlignment="Center"
                                                TextColor="{DynamicResource BaseColor}"/>
                </StackLayout>

                <Controls:CustomeButton x:Name="btnContinuePay"
                                                Text="{Resx:TranslateExtension Text=btnContinuePay}"                                                                                                     
                                                Command="{Binding ContinuePay}"/>
            </StackLayout>
        </Grid>
    </ScrollView>
</ContentPage.Content>


cs Code
using ALOROUBAH.Controls;
using ALOROUBAH.Helpers;
using ALOROUBAH.Resources;
using ALOROUBAH.ViewModel;
using System;
using Xamarin.Forms.Xaml;

namespace ALOROUBAH.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class CartPage : CustomPage
{
#region Functions
public CartPage()
{
InitializeComponent();
cToolBar.ShowCart(false);
}

    private void CheckCartItems()
    {
        if (Settings.lstCartItems.Count == 0)
        {
            lbRemoveAll.Text = AppResources.lbCartIsEmpty;
            btnContinuePay.IsVisible = slTotal.IsVisible = false;
        }
        else
        {
            lbRemoveAll.Text = AppResources.lbSetCartEmpty;
            btnContinuePay.IsVisible = slTotal.IsVisible = true;
        }
    }
    #endregion
    #region Events
    async void RmoveAllItems_Tapped(object sender, EventArgs e)
    {
        try
        {
            var vm = (CartViewModel)this.BindingContext;
            await vm.OnRemoveAllItems();
            //lvItems.ItemsSource = vm.lstClsCartItems;
            CheckCartItems();
        }
        catch (Exception ex)
        {
            Log.Report(ex);
        }
    }
    #endregion
}

}

Stacklayout visibility not working inside listview

$
0
0

Hi,I am using stacklayout inside listview like

<ListView ItemsSource="{Binding Items}" x:Name="listView" SeparatorVisibility="None" HasUnevenRows="True" SelectedItem="{Binding SelectedItem}">
                    <ListView.Header>
-------
-------
</ListView.Header>
       <ListView.ItemTemplate>
              <DataTemplate>
                   <ViewCell>
                       <Grid>
                 ------- Column1
                 -------Column2
                 -------Column3
<StackLayout x:Name="completeService"  Padding="0" VerticalOptions="CenterAndExpand" HorizontalOptions="CenterAndExpand" Spacing="0" Grid.Column="4" IsVisible="{Binding CompleteServiceVisiblity}">
                                        <!--Converter={StaticResource boolConvert}-->
                                        <Label  Text="{Binding CompleteServiceText}">
                                            <Label.GestureRecognizers>
                                                <TapGestureRecognizer NumberOfTapsRequired="1" Tapped="CompleteService_Tapped"/>
                                            </Label.GestureRecognizers>
                                        </Label>
                                        <BoxView x:Name="customBox" BackgroundColor="#658fb2" HeightRequest="1"/>
                                    </StackLayout>
                                </Grid>
                            </ViewCell>
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>

I set my stacklayout visibility false in my ViewModel like

 public class MyViewModel : INotifyPropertyChanged
    {
      private bool _completeServiceVisiblity;
        public bool CompleteServiceVisiblity
        {
            get { return _completeServiceVisiblity; }
            set
            {
                _completeServiceVisiblity = value;
                OnPropertyChanged(nameof(CompleteServiceVisiblity));
            }
        }

    private string _completeServiceText { get; set; }
    public string CompleteServiceText
    {
        get { return _completeServiceText; }
        set
        {
            _completeServiceText = value;
            OnPropertyChanged("CompleteServiceText");
        }
    }

       public MyViewModel ()
        {
            CompleteServiceVisiblity = false;
            CompleteServiceText = "Complete Service";
        }
       public event PropertyChangedEventHandler PropertyChanged;

        private void OnPropertyChanged(string property)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(property));
        }
    }

but my stacklayout is still showing!! and if I set Visibility true CompleteServiceText is not showing. Can anybody please help me what I am doing worng.

Possibility to reach built-in system icons?

$
0
0

I'm looking for the possibility to reach the platform specific icons with as little meddling in the platform specific projects.

I found this link from 2014 that states that the built-in icons are not exposed, I was wondering if there has been any change in the past four years.


Multiple Horizontal Buttons

$
0
0

Hi guys. I need to place 4 buttons in horizontal orientation, but I can't show all of them, why?

I attach an image.

Binding two lists in the ListView

$
0
0

Hi All,
I have two lists of contacts
1- The contacts which are using the apps
2- The contacts who are not using the apps

But I need to bind both lists in the same ListView...
Like in the below screenshot which has been created in core android.

my code behind snippet here--

    ContactDetails contactDetails = new ContactDetails();
            var getData = filterServices.FilterContactsAsync(BaseClass.user_id, arr, BaseClass.Token);
            RootObject objData = JsonConvert.DeserializeObject<RootObject>(getData.ToString());
            List<NonAppUser> nonAppUser = JsonConvert.DeserializeObject<List<NonAppUser>>(objData.parameters.non_app_user);
            List<RootObject1> appUsersData = JsonConvert.DeserializeObject<List<RootObject1>>(objData.parameters.app_user.ToString());

thanks

Getting error: member names cannot be the same as their enclosing type, after updating xamarin forms

$
0
0

Hi,

I installed xamarin forms 3.1.0.583944, but getting error member names cannot be the same as their enclosing type. Is it an error with the xamarin forms version, because I didn't get this type of errors with the old version, my old version was 2.5.0.121934. Screenshot adding below:

Following is the error related page:

public partial class DashBoardPage : ContentPage
    {
        public DashBoardPage(webContentList selectedGroup,bool isGroup)
        {
        }
    }

The class name and function name are same but have 2 arguments in the function.

I am calling this method from another page like below:

Navigation.PushModalAsync(new DashBoardPage(selectedItem, false));

I already found same issue here. But the solution here not solving my issue.

How to implement a simple CarouselView

$
0
0

Hello guys, I'm trying to use a simple CarouselView inside a layout.
I found that Xamarin.Forms.CarouselView (https://www.nuget.org/packages/Xamarin.Forms.CarouselView/2.3.0-pre1) is not present anymore on nuget.
So searching on the web I decided to use this one: https://github.com/alexrainman/CarouselView
This one is not working (for me) with a MasterDetailPage: the first page loaded (a Detail Page) shows nothing of the carousel (empty page), instead after i select another (or the same) page from the master the carousel works ok (but of course I need to open it in the first presented detail page too).
So, do you have some suggestions/other plugins to use?
Thanks,
Luca

How to get device width/height properly when rotating (and size views dynamically)

$
0
0

Currently, I size my views using specific values, ex:
customViewsLayout.HeightRequest = 110;
and
customViewsLayout.HeightRequest = 190
(see below)

This, unfortunately, doesn't translate when deploying on devices with display sizes that differ from the device I used to set the specific values.

My research yielded the UIKit.UIScreen.MainScreen.Bounds. Width or Height to get width and height for the deployed devices display. However when trying to use these values, when the device is rotated (portrait to landscape, or vice versa), the values don't seem to work as expected.

Trying to do % of total screen width/height to size my views dynamically. Ideally my views would size themselves to fit different displays and orientations.

I can provide screens for specificity but, the code snippet hopefully provides an outline.
EDIT: Added three screens (and a sample output log).
The first screen is on load, the second is after rotating from portrait to landscape, and the third after rotating from landscape back to portrait. The blue edges are showing the edges of the iOS simulator.

Additionally, this is how the View is declared:

private StackLayout customViewsLayout = new StackLayout
{
     Orientation = StackOrientation.Horizontal,
     HorizontalOptions = LayoutOptions.Center,
     VerticalOptions = LayoutOptions.Center,
     HeightRequest = 190,
};

Any input on how to handle dynamic view sizing properly is immensely appreciated.

Below is a small example of what I'm currently doing.

private DeviceOrientations prevOrient = DeviceOrientations.Portrait;
private static double globalWidth, globalHeight;

Overriding OnSizeAllocated

protected override void OnSizeAllocated(double width, double height)
{
    base.OnSizeAllocated(width, height);

    if (width != UIScreen.MainScreen.Bounds.Width || height != UIScreen.MainScreen.Bounds.Height)
    {
        globalWidth = width;
        globalHeight = height;
        Console.WriteLine("width: " + globalWidth);
        Console.WriteLine("height: " + globalHeight);
    }

    SetupOrientation();
}

Sample method to re-size views to fit current orientation

public void SetupOrientation()
{
    Console.WriteLine("[0:] *** Entering SetupOrientation ***");

    //      <!-- Acquire Device Orientation -->
    var orientation = DependencyService.Get<IDeviceOrientation>().GetOrientation();

    if (orientation != prevOrient)
    {
        Console.WriteLine("[0:] *** Entering SetupOrientation: code");

        //      <!-- Layout changes via Device Orientation -->
        if (orientation == DeviceOrientations.Landscape)
        {
            customViewsLayout.HeightRequest = 110;
            customViewsLayout.WidthRequest = globalWidth * 0.96;
        }
        else if (orientation == DeviceOrientations.Portrait)
        {
            customViewsLayout.HeightRequest = 190;
            customViewsLayout.WidthRequest = globalWidth * 0.96;
        }
        prevOrient = orientation;
        Console.WriteLine("[0:] *** Exit SetupOrientation: code");
    }
    Console.WriteLine("[0:] *** Exit SetupOrientation ***");
}



Help me understand Absolute layout

$
0
0

I am trying to divide the screen in to 2 parts. 75% and 25%.
I have the following XAML.

<AbsoluteLayout BackgroundColor="Gray">
    <StackLayout AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0, 0, 1, .75" BackgroundColor="Fuchsia" >
    </StackLayout>
    <StackLayout  AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0, .75, 1, .25" BackgroundColor="Aqua">
    </StackLayout>
</AbsoluteLayout> 

I have the view with a little space left over.
From what I understood, all the values are proportional. they above code says, start the fist stack layout and give 100% width and 75% height. Start the second one at 75% of the height at give it 25% of the height.
but it does not behave that way. what I am missing?

<AbsoluteLayout BackgroundColor="Gray">
    <StackLayout AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0, 0, 1, .5" BackgroundColor="Fuchsia" >

    </StackLayout>
    <StackLayout  AbsoluteLayout.LayoutFlags="All" AbsoluteLayout.LayoutBounds="0, .5, 1, .5" BackgroundColor="Aqua">
    </StackLayout>
</AbsoluteLayout>


UWP - How to make AppBar always visible when Keyboard is shown?

$
0
0

The AppBar in a UWP App disappears when the Keyboard is shown for entries.

How can I set the AppBar/Command Always visible even if Keyboard is shown?

Thanks!

Stefan


Setting Max Width for Xamarin.Forms Control

$
0
0

Hi everyone, i was creating a chat app, where use ListView with a DataTemplate to represent the messages.

The structure of the Data Template is very simple:

    <ControlTemplate x:Key="Message">
        <StackLayout VerticalOptions="FillAndExpand">           
                <Label Text="{Binding MessageBody}" HorizontalOptions= "Start" Style="{StaticResource Key=MessageBodyStyle}" />                
        </StackLayout>
    </ControlTemplate>

However i would like to limit the max length of the StackLayout or the Label control, how can i archive that? Thanks

How to display SVG image in Xamarin Forms project.

$
0
0

Hi Frineds,

I am very new in Xamarin and Xamarin Form as well. Can anybody tell me how to display Image with SVG format in Xamarin Forms? If code snippet provide, then it is really helpful.

Thanks,
Prashant N

Native Views in XAML in VS2017 ??

$
0
0

Hi,
I've read the "Natvie Views in XAML"

and downloaded the sample project(Native Switch)
..It works..

And, I made a new clean empty project with VS2017.. 15.8.8.

1) added a xaml namspace
xmlns:androidWidget="clr-namespace:Android.Widget;assembly=Mono.Android;targetPlatform=Android"
xmlns:androidLocal="clr-namespace:NativeSwitch.Droid;assembly=NativeSwitch.Droid;targetPlatform=Android"..

2) added a static instance in MainActivity

 internal static MainActivity Instance { get; private set; }
    protected override void OnCreate(Bundle savedInstanceState)
    {
        TabLayoutResource = Resource.Layout.Tabbar;
        ToolbarResource = Resource.Layout.Toolbar;

        base.OnCreate(savedInstanceState);
        Instance = this;
        global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
        LoadApplication(new App());
    }

3) used a native android widget in xaml ..

"androidWidget:TextView x:Arguments="{x:Static androidLocal:MainActivity.Instance}" Text="Native Test TextView in XAML" />
 androidWidget:Button x:Arguments="{x:Static androidLocal:MainActivity.Instance}" Text="Android BUTTON in XAML" />

the intellisense wasn't working in the xaml.

and the android <androidWidget:Button ....wasn't displayed ...
There's no error message, but it doesn't played the Button and TextView control in the xaml....

What is the cause of this problem???

I think, xamarin team doesn't take account the Documents and Sample projects.
Even the Xamarin project evolves...most of Xamarin Documents and sample projects. doesn't evolve with the Xamarins...

How can I detect the click event of any element inside a webview.

$
0
0

Hi ,
I have used a webview for displaying HTML content in description field, I have a text in description "go to Home" and on click of that text I want to navigate to another page but i am not able to detect that click on view Model or on code-behind.

I have tried to make it a link and tried to catch the click on webview Navigating and Navigated events but it did not worked , please suggest me any idea, how can I detect the click event of any element inside a webview? any suggestion will be really helpful
Thanks
Ajay

State "IsEnabled = False" is not getting retained in the UI, Xamarin Forms WPF.

$
0
0

Description:
I have two pages 1- MainPage 2- NextPage

I've added three controls in the NextPage and set IsEnabled = False for all three controls.
I'm navigating from MainPage to NextPage by Navigation.PushModalAsync(nextPage)
The first time I enter to NextPage all three controls are disabled.
But When I navigate back and re-enter to the NextPage the controls are enabled in the UI.

The IsEnabled = False is not retained. Need suggestions please.

Code:

MainPage.xaml.cs

public partial class MainPage : ContentPage
{ 
    NextPage nextPage;
        public MainPage()
        {
            nextPage = new NextPage();
            InitializeComponent();
        }
        private void Button_Clicked(object sender, EventArgs e)
        {
            Navigation.PushModalAsync(nextPage);
        }
}

MainPage.xaml

<?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:local="clr-namespace:XFWPF"
             x:Class="XFWPF.MainPage" x:Name="MyPage">
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Button Grid.Row="0" Text="Click" Clicked="Button_Clicked"/>
    </Grid>
</ContentPage>

NextPage.xaml.cs

public partial class NextPage : ContentPage``
{
    public NextPage ()
    {    
        InitializeComponent ();
            disableControls();
    }
        public void disableControls()
        {
            button1.IsEnabled = false;
            switch1.IsEnabled = false;
            switch2.IsEnabled = false;
        }
}

NextPage.xaml

            <?xml version="1.0" encoding="utf-8" ?>
            <ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
                         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                         x:Class="XFWPF.NextPage">
                <ContentPage.Content>
                    <StackLayout>
                        <Label Text="Welcome to Xamarin.Forms!"
                            VerticalOptions="CenterAndExpand" 
                            HorizontalOptions="CenterAndExpand" />
                        <Switch x:Name="switch1"/>
                        <Switch x:Name="switch2"/>
                        <Button Text="Press here" x:Name="button1"/>
                    </StackLayout>
                </ContentPage.Content>
            </ContentPage>

Thanks,
Chand

Viewing all 91519 articles
Browse latest View live


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