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

Try to move and resize a UIView after user make actions at screen #iOS

$
0
0

Hello Guys

We try build a Video Call Screen like whatsapp but we have a little problem when try to MOVE and RESIZE a UIVIEW at iOS.

When we change the UIVIEW Frame it changes its place, but it does not resize. We are using Xamarin.Forms with Custom Renderer.

On Android we can make it work using the Animations class.

Anyone can help? Follow part of code:

protected override void OnElementChanged(ElementChangedEventArgs<VideoCallControl> e)
        {
            base.OnElementChanged(e);

            if (Control == null)
            {
                videosViews = new UIView(Bounds)
                {
                    BackgroundColor = Xamarin.Forms.Color.Transparent.ToUIColor(),
                };

                SetNativeControl(videosViews);
            };

            if (this.Element == null) return;

            myVideo = new PortSIPVideoRenderView()
            {
                Frame = new CoreGraphics.CGRect(UIScreen.MainScreen.Bounds.Width - 155, 30, 135, 200),
                //AutoresizingMask = UIViewAutoresizing.None
            };

            remoteVideo = new PortSIPVideoRenderView()
            {
                Frame = new CoreGraphics.CGRect(0, 0, UIScreen.MainScreen.Bounds.Width, UIScreen.MainScreen.Bounds.Height)
                //AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight

            };

            Element.OnCallStart += (sender, evArgs) =>
            {
  var newFrame = myVideo.Frame;
                newFrame.X = UIScreen.MainScreen.Bounds.Width - 155;
                newFrame.Y = 30;
                newFrame.Width = 135;
                newFrame.Height = 200;
                myVideo.Frame = newFrame;
                //newFrame.Size = new CoreGraphics.CGSize(135, 200);
                //myVideo.RemoveConstraints(myVideo.Constraints);
                //myVideo.AutosizesSubviews = true;
                //myVideo.Layer.Frame = new CoreGraphics.CGRect(UIScreen.MainScreen.Bounds.Width - 155, 30, 20, 20);
                //myVideo.LayoutIfNeeded();
                //myVideo.LayoutSubviews();
                //myVideo.UpdateConstraints();
             };



            myVideo.initVideoRender();
            remoteVideo.initVideoRender();

            videosViews.AddSubview(remoteVideo);
            videosViews.AddSubview(myVideo);
        }

Password protect sqlite in XF application

$
0
0

Hi,
Is there a way to add a password to the sqlite database when using sqlite .net. I am using the SQLiteAsyncConnection to create the connection and it doesn't seem to support password property.

Do I have to use XAML to get controls onto a form?

$
0
0

I'm completely new to programming.

Looking at Xamarin Forms in Visual Studio Community 2015, I hoped to be able to drag and drop controls (buttons for example) onto the work area. But I can't see a way to do this.

A video I watched added a control through XAML. Is this the only way to do it?

Thanks.

Is there any one know the problem about : Label disappeared in the ListView (UWP)

$
0
0

I'm trying to update the Label.Text from view model. But it just disappeared .

But funny thing is: It would show again when I resize the window size.

I report that BUG, also upload a sample file, but if anyone could fix that, that would be really helpful.

Download Sample attachement from : https://bugzilla.xamarin.com/show_bug.cgi?id=44973

Can't remove buttons' margins and paddings in Grid on Android

$
0
0

I tried to use a grid with 3 buttons as a bottom tool bar. The grid's ColumnSpacing, RowSpacing, Padding and Margin are 0. Buttons' Margin and BorderWidth are 0 also. It works very well on iOS devices but I can't remove the gaps between buttons and grid on Android devices (refer the screenshots)

ContentPage.Padding is

<OnPlatform x:TypeArguments="Thickness"
            iOS="0, 40, 0, 0"
            Android="0, 20, 0, 0"
            WinPhone="0, 20, 0, 0" />


<StackLayout VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand" Padding="0" Margin="0" Spacing="0">
  <ScrollView  HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Padding="0" Margin="0">
    <StackLayout>
    </StackLayout>
  </ScrollView>
  <Grid Style="{StaticResource bottomGridStyle}">
    <Grid.RowDefinitions>
      <RowDefinition Height="60" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="*" />
      <ColumnDefinition Width="*" />
      <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>

    <Button x:Name="btnChargingStatus" Text="Status" Grid.Row="0" Grid.Column="0" Image="BarStatus.png" Style="{StaticResource bottomButtonStyle}" Clicked="OnButtonClicked" />
    <Button x:Name="btnStationStatus" Text="Settings" Grid.Row="0" Grid.Column="1" Image="BarSettings.png" Style="{StaticResource bottomButtonStyle}" Clicked="OnButtonClicked" />
    <Button x:Name="btnHome" Text="Home" Grid.Row="0" Grid.Column="2" Image="BarHome.png" Style="{StaticResource bottomButtonStyle}" Clicked="OnButtonClicked" />

  </Grid>

</StackLayout>

Button and grid's style
<Application.Resources>

<ResourceDictionary>
  <OnPlatform x:TypeArguments="Font" Android="8" iOS="10" WinPhone="10" x:Key="bottomButtonFontSize" />
  <Style x:Key="bottomButtonStyle" TargetType="Button">
    <Setter Property="HorizontalOptions" Value="FillAndExpand" />
    <Setter Property="VerticalOptions" Value="FillAndExpand" />
    <Setter Property="BackgroundColor" Value="Green" />
    <Setter Property="BorderColor" Value="Green" />
    <Setter Property="TextColor" Value="White" />
    <Setter Property="Font" Value="{StaticResource bottomButtonFontSize}" />
    <Setter Property="Margin" Value="0" />
    <Setter Property="BorderWidth" Value="0" />
    <Setter Property="ContentLayout" Value="Top,0" />
    <Setter Property="BorderRadius" Value="0" />
  </Style>
  <Style x:Key="bottomGridStyle" TargetType="Grid">
    <Setter Property="BackgroundColor" Value="Black" />
    <Setter Property="HorizontalOptions" Value="FillAndExpand" />
    <Setter Property="VerticalOptions" Value="End" />
    <Setter Property="ColumnSpacing" Value="0" />
    <Setter Property="RowSpacing" Value="0" />
    <Setter Property="Padding" Value="0" />
    <Setter Property="Margin" Value="0" />
  </Style>
</ResourceDictionary>

</Application.Resources>
It works well on my iPhone 6+:

But the margins and paddings (the grid's background color is black) between buttons as well as the grid and buttons can't be removed on Android phone

How to remove them on Android devices? Do I need set something in Android project's styles.xml?

Is there a "model" example of a custom renderer, taking into account error handling, memory use etc?

$
0
0

I keep seeing custom renderers being developed that contain the same errors, such as throwing null reference exceptions when navigating away from the page containing the related control. I suspect that many of them also contain (or have the potential for) memory leaks.

Is there a model example of a custom renderer that includes:
(1) Use of SetNativeControl
(2) Wiring up event handlers, and unwiring them again
(3) Memory handling that ensures all memory is released when no longer required
(4) Appropriate (i.e. as many as required, no more, no less) checks on Element, Control, newElement, oldElement

I've looked at a load of samples this morning, but most of them are so trivial that they don't show how all of the above should really be done.

Many thanks

How to replace an item in a Grid without losing the position information?

$
0
0

I want to replace a child of a grid with a new View, but without losing the position information.

Having earlier done:

                _rightViewIndex = _grid.Children.Count;
                _grid.Children.Add(someView, 1, 2, 1, 2);

I now want to replace someView with someOtherView. I can do this as follows:

                _grid.Children.RemoveAt(_rightViewIndex);
                _rightViewIndex = _grid.Children.Count;
                _grid.Children.Add(someOtherView, 1, 2, 1, 2);

But is there a way that rather than doing RemoveAt followed by Add, I can simply do a replace without losing the coordinate information?

It would seem that the following discards the position information:

                _grid.Children[_rightViewIndex] = someOtherView;

MasterDetail: Hamburger icon no visible on UWP


What would cause Java.Lang.OutofMemory exception after multiple PopAsync and Back calls?

$
0
0

I have a couple of pages with different information that is all driven from a GridLayout. After going to couple of different pages I get an Unhandled Exception.

Java.Lang.OutOfMemoryError: Failed to allocate a 12538892 byte allocation with 4025888 free bytes and 3MB until OOM

About MVVM and Lists

$
0
0

Hi there ppl, well, im tryng to make a conection between my model, model view and view... im not get sucess in data binding..

  <TableView>
    <TableRoot>
      <TableSection Title="Informações Pessoais">
        <EntryCell Label="Primeiro Nome" Text="{Binding Estudante.Nome}" Keyboard="Text" />
        <EntryCell Label="SobreNome" Text="{Binding Estudante.SobreNome}" Keyboard="Text" />
      </TableSection>
.....

this is the View part, see that i get the Binding in a Model that´s inside a View Model, here it is the view model:

        namespace AppLintAlfa.ViewModel
        {
            public class EditarViewModel : NavegacaoPadrao
            {

                public EditarViewModel(Estudante Estudante = null)
                {
                    if(Estudante == null)
                    {
                        Estudante = new Estudante();
                    }

                }

                public Estudante Estudante { get; set; }

and the code behind the View is this:

            namespace AppLintAlfa
            {
                public partial class EditarEstudante : ContentPage
                {
                    protected EditarViewModel ViewModel => BindingContext as EditarViewModel;

                    public EditarEstudante()
                    {
                        InitializeComponent();
                    }
                }
            }

I can´t get this to work, realy dont know why, im missing something ? can anyone give me a hand ?

Is there nay way of cancelling the "back" button event from the NavigationPage?

$
0
0

Topic.

Is there any way of cancelling the "back" button event from the NavigationPage, preventing the user from popping the navigation stack ?

I already can intercept the hardware back button from the main activity, but I wasn't able to capture the navigation back button.

F# compatibility was severely broken many many versions ago and still not fixed

$
0
0

Previously reported here: https://forums.xamarin.com/discussion/comment/223554/#Comment_223554

type Page(taskId, dataStoreConnection:DataStoreConnection, navigator:Navigator) as self =
    inherit MasterDetailPage(IsGestureEnabled = false, IsPresented = false, MasterBehavior = MasterBehavior.Popover)

This simple page class results in this error at compile time:

error FS0443: This type implements or inherits the same interface at different generic instantiations 'IElementConfiguration<Page>' and 'IElementConfiguration<MasterDetailPage>'. This is not permitted in this version of F#.

The PCL is built with:

I thought F# was a first class citizen in the Xamarin ecosystem. I know XamForms isn't exactly idiomatic F# but that shouldn't matter - it should still allow compilation! We have a huge codebase built on Xamarin Forms and it is all F# code. So obviously if support has been dropped this should have been communicated clearly?

Webview content loaded from REST - IFrame Embedded video displays on Android but not iOS?

$
0
0

On Android it displays the iFrame Video correctly, on iOS the video IFrame is there but blank and white, taking up the same amount of space?

Any ideas why this would be happening?

ObjectDisposedException in VisualElementRenderer (Android)

$
0
0

Hi Xamarin Team.

We have been battling an intermittent issue in the last several weeks with an System.ObjectDisposedException being thrown in the VisualElementRenderer for Android. Looking on the forums and BugZilla, there have been many similar reports with slightly different repros. However, it seems isolated to a fairly recent release of Xamarin.Android and/or Xamarin.Forms.

Here is an abbreviated stack trace showing the exception thrown.

Unhandled Exception: System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'Android.Views.GestureDetector
at Xamarin.Forms.Platform.Android.VisualElementRenderer1[TElement].Android.Views.View.IOnTouchListener.OnTouch...VisualElementRenderer.cs:104

We have a custom collection view control which we have built which is rendered using a UICollectionView on iOS, RecyclerView on Android and GridView on UWP. This view has been considered stable code for some time now and has been working flawlessly for many months. However, we noticed this exception when we upgraded to XF 2.3.3 and subsequently updated to the latest release of Xamarin.Android in the stable channel.

We note a similar issue has already been reported in several BugZilla reports.
https://bugzilla.xamarin.com/show_bug.cgi?id=42678
https://bugzilla.xamarin.com/show_bug.cgi?id=45330
https://bugzilla.xamarin.com/show_bug.cgi?id=47158

On one of the bug reports, it was suggested ObjectDisposedExceptions could be related to the new Tarjan GC which is the default in Xamarin.Android 7.0 We testing switching to MONO_GC_PARAMS=bridge-implementation=old and this solved the problem.

Looks like the new Tarjan GC Bridge may be being a little too aggressive when cleaning up. We were wondering if the peculiarities of RecyclerView may also be connected to the problem.

We are happy to put together a sample project with a repro and post a bug report if this is useful.
Anyone else been seeing this issue?

How to add checkbox control in XAML

$
0
0

Hi,

I want to add Checkbox control in Xaml page. I added below code in .Xaml page.

    <CheckBox Margin="10, 10, 3, 3"
                  Name="acceptPolicy"
                  Content = "Accept our policy"
                  FontSize="12"
                 Checked="CheckBox_Checked"/>

But i am getting below error?

Error CS0246: The type or namespace name 'CheckBox' could not be found (are you missing a using directive or an assembly reference?)

I am new to Xaml, since i am unable to find Checkbox control in Xamarin.Forms Xaml, i tried to use default Checkbox from here.

If some controls doesn't exist in Xamarin.Forms Xaml, whether can i use default Xaml controls or not?


How to show CheckBox control in xamarin.forms?

$
0
0

Hi,

I had one requirement to show the check box control in my xamarin.forms cross plotform application. I was using custom renderer for this checkbox from the following source example.

https://github.com/XLabs/Xamarin-Forms-Labs/wiki/Checkbox-Control

When I use this custom renderer, it is showing correctly in Android application. But check box is not visible in IOS application. Please let me know, do I need to do any extra configuration for display check box in Ios?

Please suggest me on this.

Thanks, Hima

Value cannot be null. Parameter: Value Iconize FontAwesome Xamarin.IOS

$
0
0

Good morning guys,
I'm using Iconize FontAwesome in a solution Xamarin Forms and ocurred a error when debug o project IOS. It's returned a message:

Value cannot be null
Parameter: Value

My AppDelegate.cs:

public partial class AppDelegate : XLabs.Forms.XFormsApplicationDelegate
{
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
Plugin.Iconize.Iconize.With(new FontAwesomeModule());

        global::Xamarin.Forms.Forms.Init();
        if(!Resolver.IsSet)
            SetIoc();

        FormsPlugin.Iconize.iOS.IconControls.Init();
        LoadApplication(new App());
        return base.FinishedLaunching(app, options);
    }

    private void SetIoc()
    {
        var resolverContainer = new SimpleContainer();
        Resolver.SetResolver(resolverContainer.GetResolver());
    }

}

And in XAML:

// iconize:IconLabel Text="fa-map-marker" TextColor="#976E56" Style="{StaticResource IconMenu}"

Already added the key and the array in info.plist.
Thank you.

MVVM and navigation

$
0
0

Hello Fellow Xamarin fans,

I have some problems with navigation. I use the mvvm light framework and navigation. But one problem I need to navigate from a contentpage to a masterdetailpage. The problem however, is does anybody has a mvvm kind of solution to use the Modal navigation? I have handled it with a message now, but I think it's not the pure mvvm way to go.

Create custom keyboard in xamarin.forms android

$
0
0

I am sending this email in addition to our talk a few days ago.

I want to present my own custom numeric keyboard.

I am developing in Xamarin.Forms for android.

I attached a sample of the keyboard.

I want to do it in my custom renderer in android in Entry view.

The custom entry code is:

public class CustomEntryRenderer : EntryRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs e)
{
base.OnElementChanged(e);
if (Control != null)
{
// what am I writing here ??
}
}
}

I will be happy to get a code sample that does it.

Binding a ListView ansynchronously using ViewModel

$
0
0

Apologies if the answer is obvious as I am brand new to mobile/xamarin dev. I am implementing a simple Employee Directory app and have hit a snag. I have my view which is a content page and my viewmodel for binding. In this view is an ActivityIndicator that shows while the data loads by binding to the ViewModel's IsBusy Property and a ListView to display the data. I can successfully load the data asynchronously. However, I cannot get the data to the ItemsSource of the ListView after loading. Please take a look at my code below and see if you can spot what I'm missing. I'm sure there's a core concept I'm not grasping somewhere.

BaseViewModel.cs

public class BaseViewModel : INotifyPropertyChanged {

  private bool mblnIsBusy;

  public bool IsBusy {
     get { return mblnIsBusy; }
     set {
        mblnIsBusy = value;

        OnPropertyChanged();
     }
  }


  public event PropertyChangedEventHandler PropertyChanged;

  public virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) {
     var handler = PropertyChanged;
     if(handler != null)
        handler(this, new PropertyChangedEventArgs(propertyName));
  }
}

EmployeeListViewModel.cs

 public class EmployeeListViewModel : BaseViewModel {
  public ObservableCollection<Employee> EmployeeList {
     get {
        return mcolEmployeeList;
     }
     set {
        mcolEmployeeList = value;
        OnPropertyChanged();
     }
  }
  private ObservableCollection<Employee> mcolEmployeeList;

  public EmployeeListViewModel() {
     mcolEmployeeList = new ObservableCollection<Employee>();
  }

  public void LoadEmployees() {
      string json = string.empty;
        EmployeeCollection colEmployees = JsonConvert.DeserializeObject<EmployeeCollection>(json);
        mcolEmployeeList = new ObservableCollection<Employee>(colEmployees.Employees);
    //left the above json empty to avoid pasting too much code (all the data retrieval) on this thread. I can confirm through debugging that this works
        //and the mcolEmployeeList gets a list of Employees
     }
  }
}

EmployeeListView.cs

public class EmployeeDirectoryListView : BaseView {

  private ListView listView;
  private ToolbarItem toolbarItem;
  private EmployeeListViewModel ViewModel;
  private bool dataLoaded;


  public EmployeeDirectoryListView() {
     this.Title = "Contact List";
     Icon = "Icon.png";
     toolbarItem = new ToolbarItem("?", "Search.png", () => {
        var search = new SearchListView();
        Navigation.PushAsync(search);
     }, 0, 0);

     ToolbarItems.Add(toolbarItem);

     ViewModel = new EmployeeListViewModel();

     var activityIndicator = new ActivityIndicator {
        Color = Color.Black,
        BindingContext = ViewModel
     };
     activityIndicator.SetBinding(ActivityIndicator.IsRunningProperty, "IsBusy");
     activityIndicator.SetBinding(ActivityIndicator.IsEnabledProperty, "IsBusy");
     activityIndicator.SetBinding(ActivityIndicator.IsVisibleProperty, "IsBusy");


     listView = new ListView() {
        IsGroupingEnabled = true,
        GroupHeaderTemplate = new DataTemplate(typeof(GroupHeaderTemplate)),
        ItemTemplate = new DataTemplate(typeof(ListItemTemplate)),
        BindingContext = ViewModel,
        IsVisible = true
     };
     listView.SetBinding(ListView.ItemsSourceProperty, "EmployeeList");


     Content = new StackLayout() {
        HorizontalOptions = LayoutOptions.FillAndExpand,
        VerticalOptions = LayoutOptions.FillAndExpand,
        BackgroundColor = Color.White,
        Children = { activityIndicator, listView }
     };

  }
  async protected override void OnAppearing() {
     if(!dataLoaded) {
        var complete = await LoadEmployees();
        dataLoaded = true;
     }
  }

  private async Task<bool> LoadEmployees() {
     ViewModel.IsBusy = true;
     await Task.Delay(10000)
     .ContinueWith(task => ViewModel.LoadEmployees());
     ViewModel.IsBusy = false;
     return true;
  }

}

ListItemTemplate.cs

public class ListItemTemplate : ViewCell
{
    public ListItemTemplate ()
    {

        var nameLabel = new Label {
            VerticalTextAlignment = TextAlignment.Center,
            FontAttributes = FontAttributes.None,
            FontSize = Device.GetNamedSize (NamedSize.Medium, typeof(Label)),
        };
        //PreferredName is a propert of object Employee
        nameLabel.SetBinding (Label.TextProperty, "PreferredName");

        var titleLabel = new Label {
            VerticalTextAlignment = TextAlignment.Center,
            FontAttributes = FontAttributes.None,
            FontSize = Device.GetNamedSize (NamedSize.Micro, typeof(Label)),
        };
                    //Position is a propert of object Employee
        titleLabel.SetBinding (Label.TextProperty, "Position");

        var information = new StackLayout {
            Padding = new Thickness (5, 0, 0, 0),
            VerticalOptions = LayoutOptions.StartAndExpand,
            Orientation = StackOrientation.Vertical,
            Children = { nameLabel, titleLabel }
        };

        View = new StackLayout {
            Orientation = StackOrientation.Horizontal,
            Children = { information }
        };
    }
 }

All pointers are greatly appreciated. Let me know if this needs clarification.

Viewing all 91519 articles
Browse latest View live


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