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

Problem to load an Image

$
0
0

Hi all,
so this is my first day in Xamarin. I am was looking the answer but nothing helped me. So :
1. I right click on Drawable->add->existing item->image.png
2. In xaml I add
3. ... but no image appear and I donw know why

From C# WPF I used to add image via : Right click on my project->properties->Resources->[image] ->add existing file .. but none wirking

Can you help me?


How to stop vidio playing in WebView

$
0
0

Dear experts,

I work on a Xamarin.Forms app (UWP!). It has a Master-Details architecture. The Master page has a ListView, and each item in it opens a corresponding Detail page. The first Detail page has only a WebView that plays a YouTube video upon loading. The second Detail view has just a placeholder label for now. Where I switch from first Detail page to the second, the sound of the video from the first Detail page is still heard. And when I switch back to the first Detail page, the video loads again, and now I hear two voices. How can I stop the video upon switching to the second Detail page and resume when going back? If this is not possible, how can I just stop the video upon leaving its Detail page?

Here is some code:

In MainMDPage.xaml.cs:

`
private void ListView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
{
var item = e.SelectedItem as MainMDPageMenuItem;
if (item == null)
return;

        var page = (Page)Activator.CreateInstance(item.TargetType);

        Detail = new NavigationPage(page);
        IsPresented = false;

        MasterPage.ListView.SelectedItem = null;

        PreviouslySelectedItem = item;
    }

`

In MainMDPageMaster.xaml.cs:

`
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class MainMDPageMaster : ContentPage
{
public ListView ListView;

    public MainMDPageMaster()
    {
        InitializeComponent();

        BindingContext = new MainMDPageMasterViewModel();
        ListView = MenuItemsListView;
    }

    class MainMDPageMasterViewModel : INotifyPropertyChanged
    {
        public ObservableCollection<MainMDPageMenuItem> MenuItems { get; set; }

        public MainMDPageMasterViewModel()
        {
            MenuItems = new ObservableCollection<MainMDPageMenuItem>(new[]
            {
                new MainMDPageMenuItem { Id = 0, Title = "Videos", TargetType = typeof(VideoPage), IconSource = @"Assets\film-strip.jpg" },
                new MainMDPageMenuItem { Id = 1, Title = "Products", TargetType = typeof(ProductsPage), IconSource = @"Assets\products.jpg" },
            });
        }

        #region INotifyPropertyChanged Implementation
        public event PropertyChangedEventHandler PropertyChanged;
        void OnPropertyChanged([CallerMemberName] string propertyName = "")
        {
            if (PropertyChanged == null)
                return;

            PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
        #endregion
    }
}`

Thanks!

How to MessagingCenter.Subscribe to same message from multiple senders

$
0
0

I want to subscribe to a message that can be sent from multiple ViewModels. Is there a more elegant solution than subscribing individually for each ViewModel, like I do below?

MessagingCenter.Subscribe<Page1Model, bool>(this, "SomeMessage", MyMethod);
MessagingCenter.Subscribe<Page2Model, bool>(this, "SomeMessage", MyMethod);

Load Platform-specific Bitmap Icon

$
0
0

Hey there. I cant see an Icon. The Label say "Rendered size = 0 x 0". I dont know where my mistake is. For the purpose of an successful test Im currently running the iOS emulator. Here is the code:

public class PlatformBitmapsPageCode : ContentPage
    {
        string icon;

        public PlatformBitmapsPageCode()
        {

            switch (Device.RuntimePlatform)
            {
                case Device.iOS:
                    icon = "Icon40.png";
                    break;
                case Device.Android:
                    icon = "icon.png";
                    break;
            }

            Image image = new Image
            {
                Source = new FileImageSource
                {

                    File = icon
                   // File = "Icon-Small-40.png"
                },
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions = LayoutOptions.CenterAndExpand
            };

            Label label = new Label
            {
                FontSize = Device.GetNamedSize(NamedSize.Medium, typeof(Label)),
                HorizontalOptions = LayoutOptions.Center,
            VerticalOptions = LayoutOptions.CenterAndExpand
        };

        image.SizeChanged += (sender, args) =>
        {
            label.Text = String.Format("Rendered size = {0} x {1}", image.Width, image.Height);
        };

        Content = new StackLayout
        {
            Children =
            {
                image,
                label

            }
        };
    }
}

So basically this code should load an Icon and give me the rendered Size of it. But the Icon does not load hence the rendered size is at 0x0.

In the tutorial I got this code from the iOS Icon name should be "Icon-Small-40.png" which should be stored in the Resources folder.
I noticed that this .png is not there. But there are a few Icons in Assets.xcassets/AppIcon.appiconset.
I copied Icon40.png from there into the Resources folder but it did not help.

What can I do to make it work?

Binding From list to labels and buttons from list

$
0
0

Hi , Im binding from my ViewModel to my view a list , but the client requested specific design , can I instead of binding to a list , bind data to labels and buttons that i have created by my self ! see picture to understand more what i mean .
thanks


StripeView in Xamarin Forms

$
0
0

I did a little research and it seems braintree and stripe are suitable for app payments.
braintree has no official xamarin bindings but there's a Stripe component by Xamarin for Android and iOS.
is it possible to use this component in Xamarin.Forms (and it's StripeView UI) ?

Native linking failed error in xamarin for GoogleSign

$
0
0

I am following this tutorial for GoogleSign in my project. https://www.pujolsluis.com/google-client-plugin-for-xamarin/ .Works fine in android. But getting Native linking failed errors while rebuild in ios.

Native linking error: clang: error: no such file or directory: '/Users/cybasetechnologies/Library/Caches/Xamarin/mtbs/builds/login2.iOS/0f92dcc98e9717a0d2643ed70077af70/obj/iPhone/Debug/mtouch-cache/FirebaseInstanceID'
Native linking error: clang: error: no such file or directory: '/Users/cybasetechnologies/Library/Caches/Xamarin/mtbs/builds/login2.iOS/0f92dcc98e9717a0d2643ed70077af70/obj/iPhone/Debug/mtouch-cache/FirebaseNanoPB'
Native linking failed. Please review the build log.
Native linking error: clang: error: no such file or directory: '/Users/cybasetechnologies/Library/Caches/Xamarin/mtbs/builds/login2.iOS/0f92dcc98e9717a0d2643ed70077af70/obj/iPhone/Debug/mtouch-cache/FirebaseCoreDiagnostics'
Native linking error: clang: error: no such file or directory: '/Users/cybasetechnologies/Library/Caches/Xamarin/mtbs/builds/login2.iOS/0f92dcc98e9717a0d2643ed70077af70/obj/iPhone/Debug/mtouch-cache/FirebaseAnalytics'
Native linking error: clang: error: no such file or directory: '/Users/cybasetechnologies/Library/Caches/Xamarin/mtbs/builds/login2.iOS/0f92dcc98e9717a0d2643ed70077af70/obj/iPhone/Debug/mtouch-cache/GoogleSignIn'
Native linking error: clang: error: no such file or directory: '/Users/cybasetechnologies/Library/Caches/Xamarin/mtbs/builds/login2.iOS/0f92dcc98e9717a0d2643ed70077af70/obj/iPhone/Debug/mtouch-cache/FirebaseCore'

Deleted bin and obj folders in both mac and visualstudio; clean and rebuid; still error persists.Please help..

Is it possible to have ItemSelected and LongPress events in same listview

$
0
0

Im wondering if it is possible to have a listview that reacts to Listview's ItemSelected event, but if i hold that view cell another event is being called. The way I tried, to make custom renderer for long press, but it overrides the ItemSelected, so only LongPress works.
Any suggestions?

Thank you!


How to fetch data from servers when app is not running?

$
0
0

This probably may be duplicate, but i kind of have specific need.

So, i need a way to fetch data from the server, when a user receive a Push Notification, while the app is not in running state.
i.e. User do receive a notification when in kill state. But doesn't execute the code to fetch data from the server. (iOS and Android)

I have achieved the same, while app is running or is in background.

I read somewhere that I may have to define a service to achieve same, but didn't quite understand it.

Will be grateful, if someone can provide their inputs.

How to create a draggable slide up panel?

$
0
0

It's nothing too elaborate, though I'm having a hard time replicating this in Xamarin Forms. As in, a view that the user can actually drag up and down.

Does Xamarin Forms have an easy solution for this problem? I've tried a bunch of libraries already and none of them seem to work/work with .Net Standard projects.

I'm currently using this solution, though it's far from perfect. Any ideas?

publish app to win store

Swagger integration with xamarin forms

$
0
0

Hello there,

I need to use swagger api codes just like drag and drop in xamarin forms project but every time I use the code generated by swagger I have to do few changes regarding restsharp and stream's writer property not found in restsharp.portable nuget package.

Please help me with the best possible solutions to fix this.

Thanks in Advance.

Two Xamarin switches alternately turn on/off

$
0
0

Hello,

I want to implement two Switches in Xamarin where one switch is on, other will automatically turn off and vice-versa. I could do this Xaml code behind as below, but I want to implement this functionality using Command or any other way to follow MVVM model. Tried to implement as Behaviors, but not successful.

Anybody has idea how to do this, thanks

Displaying a ContentView inside a ContentPage with a button click?

$
0
0

Hello all, I'll explain what I'm trying to do. I have a ContentPage (RecipePage) displaying a list of items, a searchbar and some buttons. I'd like to set up a long list of filters that the user can use to narrow down their search, and I have that as a ContentView (FilterPage) on a separate xaml file. I'd like to be able to click a button to display FilterPage while staying on RecipePage, and then another button to hide/remove the FilterPage instance once the user's done with the filters.

The project has also a master page consisting of a navbar with a single button that displays a menu, which is using the MasterBehaviour = "Popover" property. I'd like to imitate the slide-in/out visual effect that is created by that property to display the filter view, but MasterBehaviour is naturally only available to MasterDetailPage.

So, to summarize:

  • How can I display a ContentView inside a ContentPage with a button click?
  • Can the MasterBehaviour = "Popover" effect be imitated in some other way to allow the ContentView to slide in/out when the user clicks the button?

Please let me know if anything's unclear, and thank you in advance for your time.

Trying to update packages, getting an error that the package has no compatible assembly references

$
0
0

I recently updated my Xamarin build tools for an older project. I decided to go ahead and try to install the latest package updates as well. When trying to update those packages I get the following error:

Could not install package 'EntityFramework 6.2.0'. You are trying to install this package into a project that targets 'MonoAndroid,Version=v9.0', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

I've tried changing my build target to API 28, 27, 25, and 21 as other posts suggested this helped some people. I've also uninstalled and reinstalled Visual Studio for Mac. This didn't make a difference for me. What else should I look at or try to get this working?

I'm working off of a Mac running the latest version of OSX.


MVVM cascading pickers SelectedItem not firing

$
0
0

Hi. I have two pickers that I want to cascade, i.e., when a user picks a value in the first picker, the second one is populated based on the selected item.

Here's what I have:
XAML:

  <Picker x:Name="C" Title="C" ItemsSource="{Binding Cs}" ItemDisplayBinding="{Binding Value}" SelectedItem="{Binding SelectedC, Mode=TwoWay}" />
  <Picker x:Name="T" Title="T" ItemsSource="{Binding Ts}" SelectedItem="{Binding SelectedT}" />

In View Model class:

public List<KeyValuePair<string, string>> Cs { get; private set; } = new List<KeyValuePair<string, string>>();   // This gets populated in the code behind.

private KeyValuePair<string, string> _SelectedC;
public KeyValuePair<string, string> SelectedC
     {
         get => _SelectedC;
         set
         {
            _SelectedC = value;
             // Update Ts item source.
         }
     }

Problem is SelectedC's setter never fires. Please let me know if you have any ideas. Thanks.

HotReload LiveReload LiveXaml [Mac] [Windows] [nuget package] [opensource]

WebView/HybridWebView Context Menu

$
0
0

Is there any way to show the context menu? especially ios.
do you have an idea or sample? can you please share?

Thanks

BaseViewModel, Command holder, Property holder.. experimental

$
0
0

BaseViewModel

If you don't want to use fody and want to save space/time during development (creating private fields) with avoiding contructions like:

        private string _val;
        public string Val
        {
            get => _val;
            set
            {
                if(value == _val)
                {
                    return;
                }
                _val = value;
                OnPropertyChanged();
            }
        }

        private ICommand _command;
        public ICommand Command => _command ?? (_command = new Command(() =>
        {
            //check if it isn't fast double tap..oh... try/cathc etc..
        }));

You can copy and paste two classes https://github.com/AndreiMisiukevich/BaseViewModel/tree/master/Lib/BaseViewModel
Make you view model to inherit BaseViewModel and simplify code above:

        public string Val
        {
            get => Get<string>();
            set => Set(value);
        }

        public ICommand Command => Cmd() ?? RegCmd(() =>
        {
        }, TimeSpan.FromMilliseconds(300), true, ex => {
            //handle exception if you want
        });
        //first param - actionFrequency
        //second param - shouldSuppressExceptions, will be no crash if exception occurs
        //third param - onExceptionAction, if you want to handle exception after suppressing

Very small sample: https://github.com/AndreiMisiukevich/BaseViewModel/tree/master/BaseViewModel.Sample

Link: https://github.com/AndreiMisiukevich/BaseViewModel

I'm not sure, that it is useful and makes sense at all :) experimental

All properties are stored in dictionary.

BottomNavigationView option for TabbedPage on Android

Viewing all 91519 articles
Browse latest View live