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

Why is the ReturnCommandParameter not being passed from an Entry to ICommand?

$
0
0

Hi,

I'm trying to pass the text from a entry box, but it doesn't seem to be passing it. I got it working for a search bar using the same concept.

xaml:
<Entry x:Name="entryBox" Placeholder="Enter chat text here:" ReturnType="Send" Keyboard="Plain" BindingContext="{Binding Source={viewModels:ChatroomViewModel}}" ReturnCommand="{Binding SendCommand}" ReturnCommandParameter="{Binding Source={x:Reference entryBox}, Path=Text}" Completed="EntryTextSend_Completed" />

ViewModel:

    public class ChatroomViewModel : INotifyPropertyChanged
        {
            public event PropertyChangedEventHandler PropertyChanged;

            // ManualResetEvent instances signal completion.  
            private static ManualResetEvent connectDone = new ManualResetEvent(false);
            private static ManualResetEvent sendDone = new ManualResetEvent(false);
            private static ManualResetEvent receiveDone = new ManualResetEvent(false);

            protected virtual void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
            {
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
            }

            public ICommand SendCommand => new Command<string>((string query) =>
            {
                Console.WriteLine("query: " + query);
                Send(query);
            });

            private void Send(String data)
            {
                try
                {
                    Socket client = LoginPageViewModel.clientSocket;
                    // Convert the string data to byte data using ASCII encoding.  
                    byte[] byteData = Encoding.ASCII.GetBytes(data);

                    // Begin sending the data to the remote device.  
                    client.BeginSend(byteData, 0, byteData.Length, 0, new AsyncCallback(SendCallback), client);
                }
                catch (SocketException ex)
                {
                    /*connected = false;
                    chatRoomPage.UpdateChatWindow("<Server> - You are disconnected from the server!");
                    chatRoomPage.setStatusLabel("Disconnected.");*/
                    Console.WriteLine("SocketException: " + ex.Message);
                }
            }

            private static void SendCallback(IAsyncResult ar)
            {
                try
                {
                    // Retrieve the socket from the state object.  
                    Socket client = (Socket)ar.AsyncState;

                    // Complete sending the data to the remote device.  
                    int bytesSent = client.EndSend(ar);
                    Console.WriteLine("Sent {0} bytes to server.", bytesSent);

                    // Signal that all bytes have been sent.  
                    sendDone.Set();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.ToString());
                }
            }
        }

how to set title of navigation bar to center?

$
0
0

in xamarin forms how to set title of navigation bar to center?

iOS DateTime issue with Xamarin.Forms 4.2 and Prism?

$
0
0

Apparently if you update Xamarin Forms to the latest version, make a bindable DateTime property with Prism, and try to add time to it, it does not work anymore.

I have this Prism property MyDate:

private DateTime? _myDate;
public DateTime? MyDate
{
    get { return _myDate; }
    set { SetProperty(ref _myDate, value); }
}

Then I have a calendar where I bind the SelectedDate to MyDate:
<syncfusion:SfCalendar x:Name="calendar" SelectedDate="{Binding MyDate, Mode=TwoWay}" />

Then I have a button that is supposed to take the selected date, and add the current time, and print it using a label:
<Label Text="{Binding MyDateFormatted}"></Label>

private string _myDateFormatted;
public string MyDateFormatted
{
    get { return _myDateFormatted; }
    set { SetProperty(ref _myDateFormatted, value); }
}

// ...

private DelegateCommand _formatCommand;
public DelegateCommand FormatCommand =>
    _formatCommand ?? (_formatCommand = new DelegateCommand(ExecuteFormatCommand));

private void ExecuteFormatCommand()
{
    try
    {
        MyDate = MyDate.Value.Date.Add(DateTime.Now.TimeOfDay);
        MyDateFormatted = $"{MyDate.Value.ToLongDateString()} @ {MyDate.Value.ToShortTimeString()}";
    }
    catch (Exception)
    {
            // handle
    }
}

In android everything works. In iOS it does not add the current time to MyDate and it always shows 12am.

  • If instead of a Prism property I use a regular property such as public DateTime? MyDate { get; set; } it works in iOS too.
  • If instead of a calendar I set MyDate manually on page load, such as MyDate = DateTime.Today.Date and keep the Prism property, it works too.

I don't understand the problem. Is it a Prism property issue? A xamarin forms issue? A calendar issue?
Here's the repo to reproduce it in iOS.
https://github.com/stesvis/DateTimeTest

What does @BrianLagunas think? Could it be due to Prism and some incompatibility with the latest Xamarin Forms?
Thanks everybody

How to get email id suggestion while typing on entry field?

$
0
0

I want to implement an email id suggestion on the entry field like in the above image. I googled this question but I have not found anything. I am having doubt whether this is a feature of xamarin or feature of IOS devices? Can I implement this feature with xamarin or not?

Images not rendering on some pages on Android (iOS works fine)

$
0
0

Hi!
I came across a weird issue lately in Android. While Image elements work fine on most Pages, there are two that won't display them. I tried with both built in Image elements, and the FFImageLoader library.
What's even weirder, is that the exact same image tag with the same hardcoded source works on some pages, but won't render on some others. Avery other element seems to be working fine, and iOS works just as it should everywhere. This seems to be Android-specific.

Does anyone happen to know what's going on?
Thanks!

Encrypt Locally of Remotely? Which one is more Secure?

$
0
0

Hi,

I have a sign in page and I want to pass the email and password of the user but I want to discuss with you guys which one is more secure? to salt and hash the password locally and send it like this:

var content = new FormUrlEncodedContent(new[]
{
    new KeyValuePair<string, string>("email", TextBoxSignupEmailAddress.Text),
    new KeyValuePair<string, string>("salt", password_salt),
    new KeyValuePair<string, string>("hash", password_hash),
});

Or just send the email and password and then salt it and hash it on remote like this:

var content = new FormUrlEncodedContent(new[]
{
    new KeyValuePair<string, string>("email", TextBoxSignupEmailAddress.Text),
    new KeyValuePair<string, string>("password", password)
});

What is your advise...

Thanks,
Jassim

Which function to tally total from rows in a table?

$
0
0

I am assuming that it's going to be a job for linq, but I cannot figure out how to make it work?

My biggest problem is that I am working on a field within the table.
I assume the code should look like this (minus my hideous oversimplification of the aggregate function)

public void GetSomeTotals()
{
    obervablecollection<dbtable> tabledata = await tablerepo.getitems();

    int totalItems = tabledata.Aggregate(func: (result, item) => result += item);
}

pseudo code

public void GetSomeTotals()
{
    obervablecollection<dbtable> tabledata = await tablerepo.getitems();
    int totalitems; 
    tabledata. ??? ( x => totalItems += x.Quantity);
}

I cannot get the second example to work, because the int object is outside of the scope.

Forms app using FreshMVVM and navigation bar colors in modal pages

$
0
0

I have a simple XF app that leverages FreshMVVM. All works great, but I am using the NavigationPage.TitleView element to customize the navigation bar layout. When I push a modal page, the modal page's navigation coloring isn't correct. If you push as a non-modal it works fine.

Notice in the image below when the page shows the navigation bar is blue, but the modal shows white. How can this be changed so the dialog nav bar is consistent with the main page (ie, blue)?

The source for this example can be downloaded from here.

Here is my app.xaml.cs which sets everything up. Notice I am setting the colors for the navigation bar.

public partial class App : Application
{
    public App()
    {
        InitializeComponent();

        MainPage = new MainPage();

        var mainPage = FreshPageModelResolver.ResolvePageModel<MainPageModel>();
        var mainNavigation = new FreshNavigationContainer(mainPage);
        mainNavigation.BarBackgroundColor = Color.FromRgb(0, 69, 140);
        mainNavigation.BarTextColor = Color.White;

        MainPage = mainNavigation;
    }
}

MainPage.xaml

<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"
             x:Class="SampleApp.MainPage">

    <NavigationPage.TitleView>
        <StackLayout HorizontalOptions="Center" 
                     VerticalOptions="Center">
            <Label Text="Page Title" />
        </StackLayout>
    </NavigationPage.TitleView>

    <StackLayout>
        <!-- Place new controls here -->
        <Label Text="Welcome to Xamarin.Forms!" 
               HorizontalOptions="Center"
               VerticalOptions="Center" />
        <Button Command="{Binding OpenDialog}" 
                Text="Open Dialog"
                VerticalOptions="End" />
    </StackLayout>

</ContentPage>

MainPageModel

public class MainPageModel : FreshBasePageModel
{
    // template command
    public Command OpenDialog
    {
        get
        {
            return new Command(_ =>
            {
                CoreMethods.PushPageModel<DialogPageModel>(null, modal: true);
            });
        }
    }

}

DialogPage.xaml

<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"
             x:Class="SampleApp.DialogPage">

    <NavigationPage.TitleView>
        <StackLayout HorizontalOptions="Center" 
                     VerticalOptions="Center">
            <Label Text="Page Title" />
        </StackLayout>
    </NavigationPage.TitleView>

    <ContentPage.Content>
        <StackLayout>
            <Label Text="Dialog Page"
                   VerticalOptions="CenterAndExpand" 
                   HorizontalOptions="CenterAndExpand" />
            <Button Text="Close"
                    Clicked="Button_Clicked" />
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

How to implement TapGesture of Custom ViewCell in MVVM?

$
0
0

Hi everybody, have a good day!

In my HomePage, I have a ListView with ItemTemplate is another Custom ViewCell (another XAML file)
In Custom ViewCell have a Label and that Label attach a TapGesture

How to fire TapGesture event of Label in Custom ViewCell from HomePageViewModel?

I'm using pure Xamarin.Forms MVVM!

Thank you!

How to Change selected Tab Background color in Tabbedpage in Xamarin.forms

$
0
0

I want to change selected tab background color like attached image. Please send me any reference code or links.
Thanks in Andvance.

BackgroundIMage Loop

$
0
0

Hello everyone,
I have a problem with the background of my application since it is repeated in the form of a mosaic and in theory I should not do that, it is coded in xaml, in an emulator android looks good without the error that I mention, but when running it in IOS emulator this problem appears, I am a little doubtful where I should investigate that problem because in the xaml I have nothing other than the property "BackgroundImage", I would like to know if someone has had this problem and if it could solve it, also Only as an extra when I wanted to run the application. I did not leave because I did not find the resources but only added the background images and everything was fine, thanks for reading, greeting!

This my code 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="DefinityFirst.Mobile.Pages.Login"
BackgroundImage="LoginBackground.png"
NavigationPage.HasNavigationBar="False"
>
<ContentPage.Content>

    <StackLayout Padding="0,60,0,15">
        <StackLayout HorizontalOptions="CenterAndExpand" VerticalOptions="StartAndExpand" Padding="2,0,2,0" >

          <Image Source="appIcon.png" x:Name="logoOffi" ></Image>

            <Label HorizontalOptions="Center" FontAttributes="Bold" FontSize="22" Text="Definity First" TextColor="White" FontFamily="Robot" />
            <Label HorizontalOptions="Center" FontSize="14" Text="Dream impossible. We build it." TextColor="White" />
        </StackLayout>
        <StackLayout HorizontalOptions="FillAndExpand" VerticalOptions="CenterAndExpand" Padding="15,0,15,0">
            <ActivityIndicator x:Name="activityIndicator" Color="Black" IsRunning="false" />
            <Button BackgroundColor="#174387" x:Name="btnLogin" Text="LOGIN &amp; ENTER NOW" TextColor="White"  FontSize="14" /> 
            <Label x:Name="labelError" IsVisible="False"/>
        </StackLayout>
        <StackLayout VerticalOptions="EndAndExpand">
            <Label HorizontalOptions="Center"  Text="2016 Definity First. All rights reserved" TextColor="White"/>
        </StackLayout>
    </StackLayout>
</ContentPage.Content>

Background Android & IOS

Collapsing Toolbar Layout in Xamarin Forms

Exif data from photo

$
0
0

I'm looking for a way to extract the Exif data (specifically, gps coordinates where photo was taken, when available) from images on the phone, both iOS and Android.

XLabs Media Picker doesn't provide this information, and neither does the Xamarin Media Picker plug-in. None of the meta data for an image is set with either of these solutions. Has anybody implemented a way to get this information from an image on the phone?

ListView with MVVM - TapGestureRecognizer not working

$
0
0

Hi,

I'm trying to go the MVVM route and avoid doing stuff directly in the code-behind, I'm finding that trying to detect a row being clicked to invoke a command painful to implement. It would seem that there's no ItemSelected that takes a Command (but it's okay if I wanted to invoke an action in my code-behind), which is a shame, so I've tried to use the TapGestureRecognizer with no success...

XAML...

        <ListView 
            CachingStrategy="RecycleElement"
            ItemsSource="{Binding FilteredMessages}" 
            HasUnevenRows = "true"
            SelectedItem = "{Binding SelectedMessage}">


            <ListView.ItemTemplate>
              <DataTemplate>
                <ViewCell>
                    <StackLayout Orientation="Vertical">
                        <StackLayout Orientation="Horizontal">
                            <Label Text="{Binding Scheduled}"/>
                        </StackLayout>
                        <StackLayout Orientation="Horizontal">
                            <Label Text="{Binding Message}"/>
                            <Label.GestureRecognizers>
                                <TapGestureRecognizer Command="{Binding TapCommand}"></TapGestureRecognizer>
                            </Label.GestureRecognizers>
                        </StackLayout>
                    </StackLayout>
                </ViewCell>
              </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

The View Model...

    public ContactDetailViewModel()
    {
    ...
        TapCommand = new Command(HandleAction);
    }


    void HandleAction (object obj)
    {
        Console.WriteLine("***** DOESNT GET CALLED :-( *****");
    }

I've tried to put the GestureRecognizers at different layers in the xaml (i.e. at the StackLayout, ViewCell and ListView), but none invoke my callback method, but it would appear that it's capturing the event, because the cell doesn't go grey; which is the default behaviour when I click the cell.

Any ideas what I'm overlooking here?

I could fallback to using an ItemSelected in the code-behind and delegate a call through to the ViewModel, but that's not clean.

I appreciate any insights.

Thanks,
Rob.

UWP - Cannot resolve Assembly or Windows Metadata file

$
0
0

Hi All,

Everything was rolling along smoothly until a few days ago when UWP all of a sudden stopped building after pulling a new version from VSTS (git) with the errors:

  • Cannot resolve Assembly or Windows Metadata file 'Type universe cannot resolve assembly: X.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.'
  • Could not copy the file "obj\x86\Debug\MainPage.xbf" because it was not found.
  • Could not copy the file "obj\x86\Debug\App.xbf" because it was not found.
  • Could not copy the file "obj\x86\Debug\X.Mobile.UWP.xr.xml" because it was not found.

I have a solution structure of the following:

  • X.Core (.NET Standard class library)
  • X.Mobile (.NET Standard PCL)
  • X.Mobile.UWP (UWP specific project)

UWP references Mobile, and Mobile references Core (Core is also referenced by a web API project).

The commit that I pulled from source control did not have any changes to the X.Mobile.UWP .csproj file.

Things I have tried:

  1. The obligatory clean and rebuild.
  2. Delete all obj and bin folders for the entire solution.
  3. Remove and re-add all references in the .UWP project.
  4. Upgrade Xamarin.Forms to the latest stable (3.1.0.637273).
  5. Remove and re-add X.Core reference in the X.Mobile project.
  6. Delete C:\Users\%username%.nuget folder.
  7. Update Microsoft.NETCore.UniversalWindowsPlatform to the latest stable (6.1.5).
  8. Change the target version to all available versions - we've been running on build 16299 for several months.

And I've been beating my head against this problem on and off for days now. Android and iOS projects build just fine, which is ironic considering UWP has been our most stable platform. Anyone have any insight?

EDIT:
After adding a reference to X.Core to the X.Mobile.UWP project directly, I can compile. This shouldn't be the answer though since the UWP project never directly references the Core project.


Which is faster SQL query statement or Web API

$
0
0

Hi Xamarin Forms

Can I have a help from you guys I want to clear my mind which is much faster when querying data from DB is it directly writing SQL query statement(SELECT statement) or writing a Web API, Lets set aside the security first for I want to know faster return of data from database also my data stores links of image stored in my server rather than storing the actual image to DB

so which is more faster and more recommendable for faster performance of my app

Thanks in Advance :)

IOS page not fit vertically

$
0
0

Hi Guys

I am developing Xamarin Forms project. When i check IOS output view, launched my login page is perfect. Once login successfully it's navigate to next page, In this case when launched after login page, every page is not fit vertically from bottom to top. Every page have some space on the top. I don't know how i am clear this issue. Anyone please give the solution. I have attached error screenshot for your reference. Kindly check the error screenshot give me any solution.

Advance thanks!!!

Shell : Custom icon for selected tab

$
0
0

Hello everybody,

I'm playing with the COOL xamarin shell, but I didn't found a way to change icon of the selected tab.

<TabBar Route="sections">
        <Tab Title="home">
            <Tab.Icon>
                <FontImageSource FontFamily="{StaticResource AppIcons}" Glyph="{x:Static framework:Icons.HomePage}" />
            </Tab.Icon>
            <ShellContent ContentTemplate="{DataTemplate home:HomePage}" Route="home" />
        </Tab>
</TabBar>

The goal is to use Icons.HomePageFilled instead of Icons.HomePage for this tab only when it's selected. Same logic should apply to other tabs.

I think I got lost in the solutions found on the web. They talk about Custom renderers, Visual states, effects etc ...
But I do not know if it is feasible and what is the ideal solution

why does ios 'email.compose' cause nullexception when including attachment but Android doesnt

$
0
0

Using the experimental
I have this code which sends a gps (track file) via email
Works fine in Android but falls over in the appdelegate of iOs with null exception - its definitely the attachment -remming it out eliminates the issue
var message = new EmailMessage
{
Subject = "Mygps Track",
Body = "My gpx track which can be viewed in google earth"
} ;
ExperimentalFeatures.Enable("EmailAttachments_Experimental");
if (File.Exists(fnm3))
{
message.Attachments.Add(new EmailAttachment(fnm3));
}
await Email.ComposeAsync(message);
//.........................................
Anyone any ideas why it should behave differently with iOs ?

I am checking that the file exists so its not a null attachment or anything like that
I am stumped - anyone have any ideas ? I know I am using the 'experimental'stuff but does this not work in iOs?

Table is not created

$
0
0

Hi

I'm using SQLite as a local database for my mobile application (Android); by using a SQLiteAsyncConnection I'm trying to create a new table, but it it's not working. No exception is raised, the code seems to execute just right, but the table is not created.

A sample of the code:
How the connection is created:

        public SQLiteAsyncConnection GetAsyncConnection()
        {
            try
            {
                var path = GetDatabaseFileLocation();

                var conn = new SQLiteAsyncConnection(path, false);

                return conn;
            }
            catch (Exception ex)
            {
                string message = ex.Message;
            }

            return null;
        }

        public string GetDatabaseFileLocation()
        {
            var sqliteFilename = "my_database.db3";
            string documentsPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal); // Documents folder
            var path = Path.Combine(documentsPath, sqliteFilename);
            return path;
        }

The method to create the table:

        public void CreateTable()
        {
            var asyncConnection = DependencyService.Get<ISQLite>().GetAsyncConnection();

            // This does not work
            asyncConnection.CreateTableAsync<MyModel>();

            // This does not work either
            //asyncConnection.GetConnection().CreateTable<MyModel>();
        }

None of the above statements seem to work ...

Anyone know what is going on?

Viewing all 76418 articles
Browse latest View live


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