xamarin.forms

How to display alert from ViewModel

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-06 20:42:32
问题 newbie here. I want to display alert from ViewModel . problem: The name DisplayAlert does not exist in the current context How to do that? Below is my code. -- XAML <Button x:Name="BtnLogin" Command="{Binding LoginCommand}" BackgroundColor="Green" TextColor="White" WidthRequest="150" HeightRequest="60" Text="Login" /> --- ViewModel : class LoginViewModel : ViewModelBase { private string _username; public string Username { get { return _username; } set { _username = value; OnPropertyChanged();

How to get the index of a clicked CollectionView element?

﹥>﹥吖頭↗ 提交于 2021-02-05 12:15:55
问题 I have elements added inside a CollectionView . Inside this CollectionView , I have an ImageButton wich make visible other ImageButton . I need to get the index of the element by clicking the first ImageButton and use it in the Command of the second ImageButton . Is that posible? My xaml: <StackLayout> <CollectionView ItemSource="{Binding myItemSource}"> <CollectionView.ItemTemplate> <DataTemplate> <ContentView> <ImageButton x:Name="FirstImageButton" Command={Binding MakeVisibleNewButton}/> <

Upload a file(any doc file ) in xamarin forms

不问归期 提交于 2021-02-05 12:08:14
问题 How to browse and upload a file (not a pic) in xamarin forms? Ex. When i click on button event. its open the file manger of mobile and then pick any doc from mobile and then upload it. 回答1: First off, you need to have permission to read and write to the users phone Request permission as below using Plugin.FilePicker; using Plugin.Permissions; async Task<bool> RequestStoragePermission() { //We always have permission on anything lower than marshmallow. if ((int)Android.OS.Build.VERSION.SdkInt <

Upload a file(any doc file ) in xamarin forms

独自空忆成欢 提交于 2021-02-05 12:02:06
问题 How to browse and upload a file (not a pic) in xamarin forms? Ex. When i click on button event. its open the file manger of mobile and then pick any doc from mobile and then upload it. 回答1: First off, you need to have permission to read and write to the users phone Request permission as below using Plugin.FilePicker; using Plugin.Permissions; async Task<bool> RequestStoragePermission() { //We always have permission on anything lower than marshmallow. if ((int)Android.OS.Build.VERSION.SdkInt <

View to different view model binding in Xamarin forms

我与影子孤独终老i 提交于 2021-02-05 12:01:20
问题 I am having 2 views in my application and each of them having associated view model .I am having a requirement like access the second viewmodel methods form the first view's xaml.cs file (I don't want to bring all the logic in second viewmodel to first one ,that's why keeping both view model as such ) Is there any way i can achieve the same ? 回答1: You can do that by making a ViewModelLocator using MVVMLight, it will create a singleton pattern and you can access ViewModel anywhere using

Xamarin Forms: Grid button UI breaks when click restart button

自作多情 提交于 2021-02-05 11:48:40
问题 I am using a button inside the grid for showing letters to implement a Word search game . Initially, the UI is looking good, but when clicks the play again button the UI breaks. Screenshot: Code for the setting button inside grid: void SetGridLayout(char[,] matrixToPrint) { int numRows = matrixToPrint.GetLength(0); int numCols = matrixToPrint.GetLength(1); gridLayout.HorizontalOptions = LayoutOptions.FillAndExpand; gridLayout.SetBinding(Button.HeightRequestProperty, new Binding("Width",

Xamarin Forms: Grid button UI breaks when click restart button

若如初见. 提交于 2021-02-05 11:47:32
问题 I am using a button inside the grid for showing letters to implement a Word search game . Initially, the UI is looking good, but when clicks the play again button the UI breaks. Screenshot: Code for the setting button inside grid: void SetGridLayout(char[,] matrixToPrint) { int numRows = matrixToPrint.GetLength(0); int numCols = matrixToPrint.GetLength(1); gridLayout.HorizontalOptions = LayoutOptions.FillAndExpand; gridLayout.SetBinding(Button.HeightRequestProperty, new Binding("Width",

Xamarin Forms CollectionView Custom Layout Design

末鹿安然 提交于 2021-02-05 11:44:26
问题 In the app that I'm designing, I use collectionview to show loads of images. And this is my current design. And this is the design I want. where the images that are shorter in height will have the next image fill up the white spaces. Heres my code: <CollectionView x:Name="cv_WallPapers" ItemsSource="{Binding Results, Mode=TwoWay}" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" SelectionMode="Single" SelectionChanged="cv

How do I bind to MasterPage viewmodel inside a BindableLayout

陌路散爱 提交于 2021-02-05 11:30:07
问题 I am trying to bind my Command property to the Command in my MasterDetailPage view model. I tried defining the name property for the master page and setting that as the reference source, but it does not seem to bind to the viewmodel. For context, the List MenuItems is a property in the same Viewmodel and the Title binds just fine. I believe I am not setting the Source for the command correctly, but not sure how to fix it. Also, I am using Prism, so the viewmodel is mapped in app.xaml already.