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

Label visibility true when entry text property is not empty

$
0
0

Hello Guy's

      I have a create application but i am facing a issue.
      I want to label visibility true when entry text property is not empty and when entry text property not empty then label visibility false.
      I want to do this thing only Xaml page not Cs. page.

         <StackLayout  Grid.Row="1" Orientation="Vertical" BackgroundColor="Transparent" Spacing="10">
                <Label x:Name="lblUserName" Text="User ID" FontSize="Medium" TextColor="White" />
               <Entry x:Name="enrtyUserName" Placeholder="User ID" FontSize="Medium" PlaceholderColor="Gray" BackgroundColor="White" />
        </StackLayout>

Is it possible in xaml coding use like value converter or triggers.

Thanks in advance


How do you clear selection in CollectionView in multiselect mode?

$
0
0

The ObservableCollection has a list of items with the first item called 'Any', the plan is to clear the other selected items when 'Any' is selected and clear 'Any' when other items are selected.
How would such a feature be implemented?
The code below is utilizing MVVMHelpers.

ViewModel

public class SimpleViewModel : BaseViewModel
{
public ObservableCollection<FilterType> FilterOptions { get; private set; }
        public ObservableCollection<object> SelectedOptions
        {
            get => selectedOptions;
            set {  SetProperty(ref selectedOptions, value);  }
        }

public string SelectionList
        {
            get => _selectionList;
            set  {  _selectionList = value;
                OnPropertyChanged("SelectionList");
            }
        }

public SimpleViewModel()
        {
            FilterOptions = new ObservableCollection<Widget>();

             FilterOptions.Add(new Widget() { Name = "Any" });
            FilterOptions.Add(new Widget() { Name = "Wilma" });
            FilterOptions.Add(new Widget() { Name = "Barney" });
            FilterOptions.Add(new Widget() { Name = "Betty" });
            FilterOptions.Add(new Widget() { Name = "Pebbles" });
            FilterOptions.Add(new Widget() { Name = "Bambam" });

            SelectedOptions = new ObservableCollection<object>();

            // Add collection changed handler
            SelectedOptions.CollectionChanged += SelectedOptions_CollectionChanged;

            UpdateSelectionList();
        }

private void SelectedOptions_CollectionChanged(object sender, 
                                               System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {  }

        void UpdateSelectionList()
        {
            SelectionList = String.Join(", ", SelectedOptions.Cast<Widget>().Select(t => t.Name));
        }
}

XAML

     <StackLayout>
            <StackLayout Orientation="Horizontal" HorizontalOptions="Center">
                <Label Text="Selected : " FontAttributes="Bold" />
                <Label Text="{Binding SelectionList}" />
            </StackLayout>
            <CollectionView x:Name="collectionView" ItemsSource="{Binding FilterOptions, Mode=OneWay}" 
                                           SelectionMode="Multiple"
                            SelectedItems="{Binding SelectedOptions, Mode=TwoWay}">
                <CollectionView.ItemTemplate>
                    <DataTemplate>
                        <Grid Padding="10">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>                           
                            <Label Grid.Column="0"
                               Text="{Binding Name, Mode=OneTime}" />
                        </Grid>
                    </DataTemplate>
                </CollectionView.ItemTemplate>
            </CollectionView>
        </StackLayout>

An example

Use Confirm Alert In Command

$
0
0

hi i want display confirm alert in command
its show but not worked confirm and cancel

        public void Execute(object parameter)
                 {
                     var r= App.Current.MainPage.DisplayAlert("Question?", "Would you like to play a game", "Yes", "No");
                          if(r.Result)
                               { 
                                    // not back this

                             AppDatabase db = new AppDatabase();
                               db.RemoveFavoriteById((int)parameter).Wait();
                          RefreshFavorites();
                                }

                   }

Not every label updates

$
0
0

I want to write a settings page where, when you choose a language from a picker, the language changes for the whole page. I use Resx files and EventHandler (PropertyChanged...) for this.
I call the EventHandler when the value of the selected element (CurrentCulture) of the picker changes.

In XAML:

<!--SETTINGSPAGE_LABEL_LANGUAGE returns (get;) text from resx as string with the name SETTINGSPAGE_LABEL_LANGUAGE -->
            <Label Text="{Binding SETTINGSPAGE_LABEL_LANGUAGE}"
                    Grid.Row="0" Grid.Column="0"/>

<!--LanguageList is a string[] with all Languagenames in their specific Language (For example: Deutsch, English)
CurrentCulture saves the name of the culture (set triggers onpropertychanged) -->
            <Picker ItemsSource = "{Binding LanguageList}"
                    SelectedItem="{Binding CurrentCulture}"/>

Some code from the ViewModel:

 public string CurrentCulture
 {
        get
        {
           return _currentCulture;
        }

       set
       {
           MainThread.BeginInvokeOnMainThread(() =>
           {
                _currentCulture = value;
//Im using the MVVM with Controllers. Thats why i named it ViewModelController
                _settingsViewModelController.SetCurrentAppCulture(_currentCulture);
          });
      }
}

and

public static void SetCurrentAppCulture(string cultureCode, BaseViewModel baseViewModel = null)
{
      CultureInfo cultureInfo = new CultureInfo(cultureCode);
//I just tried all methods to set the culture in any way, but nothing helped.
//Like so:
      CultureInfo.CurrentCulture = cultureInfo;
      CultureInfo.CurrentUICulture = cultureInfo;
      Thread.CurrentThread.CurrentCulture = cultureInfo;
      Thread.CurrentThread.CurrentUICulture = cultureInfo;

//The if-Statement can be deleted. I fixed the error, when the baseViewModel were null.
      if (baseViewModel != null)
          baseViewModel.OnEveryPropertyChanged();
}

Now the problem is that
does not reload every label when PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(String.Empty)); is called.

But now comes the strange thing.

I currently have 2 languages. When I change the language for the first time, sometimes nothing happens or everything is translated (as it should be).
When I change the language again, not all labels etc. are translated.

If I change the language again, the languages of the texts are inverted (language 1 becomes language 2 and vice versa).
And when I invert the lyrics, it stays inverted even if I change the language again and change it ...

Label1 had language1 -> Label1 now has language 2
Label2 had language2 -> Label2 now has language 1
Label3 had language1 -> Label3 now has language 2

But if I set a breakpoint now, this will not happen.
I get the feeling that it doesn't load fast enough, which I find quite funny, since I do everything on the main thread.

I ran also in the problem, that i can only change the language of the current and future views.

My mainController has a list of all views which I have opened before and can call up again with the Navigator (PopAsync). I have tried to change the language of the old views using this list, but unfortunately this does not work.

Does anyone have an idea how I can solve these two problems?
I've been searching for days and I'm getting desperate.

How to insert the items selected from the collection view into the database?

$
0
0

Hello Sir,
I' trying to insert the items selected from the collection view into the database, here all the items are getting inserted into a single row, but I want every item to be inserted separetly into the databse. PLease help me. below is the code I'm using.

private void roleview_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var rolename = e.CurrentSelection;
            string msg = string.Empty;
            msg = "Selected Permission are \n";
            for (int i = 0; i < rolename.Count; i++)
            {
                var rolenames = rolename[i] as user_permission;
                msg += $"{rolenames.form_name}\n";
            }
            ////DisplayAlert("Demo", msg, "OK");
            activity.Text = msg;
        }

So I'm directly trying to insert the activity.Text result into the databse.
Thanks in advance

Curved Horizontal List in Xamarin Forms

$
0
0

How can we achieved curved horizontal list scroll in Xamarin Forms. I have found few plugins and custom renderers for horizontal list BUT the problem is for curved UI for list.

Are there ay such plugins or custom renderer available for curved UI as shown in image.

How to open hindi keyboard in App using xamarin forms

$
0
0
I want to open hindi keyboard for user entry and also i want to convert english language into hindi language in whole application.please help

Get counrty code picker or popup


How do I get the string result of EvaluateJavascript Xamarin Forms?

$
0
0

Hello,

i want to get the value of input field from an html site and tried to use this:
string x = webView.EvaluateJavaScriptAsync("document.getElementById('test').value;")

this is not working, can anyone help me??

Thanks

Databinding Source

$
0
0

Hi,

I want to set a string in another class say App.Xaml.cs

public string MyValue = "somevalue";

How can i bind the text of a label to that MyValue item? I'm not sure how the Databinding source works or how I need to wire it up.

I've tried this which didnt work

Can't see Photos Permission - Xamarin Forms iPhone

$
0
0

Hi,
I have set the Privacy - Photo Library Usage Description property and text in the Info.plist file but it doesn't seem to be working - by that I mean I can't see Photos when I goto Settings > MyApp

I have Privacy - Location When in Use Usage Description set and that works fine (i.e. it shows up in iphone settings for the app)

Bundle Name, Version, Identifier all match up and I'm not sure what else i'd need to set.

Any ideas how to fix? It was working previously - i have recently signed up to Apple Developer / Connect instead of the free profile, so have had to create a bundle ID, App name etc. so not sure if that has caused this.

How to save a SkiaSharp drawing?

$
0
0

I must be missing something. I started with the FingerPainting part of the TouchTrackingEffectDemos. After drawing something, I want to save it so I added a Save Button (just like there is a Clear Button). The Save button is supposed to save the drawing to my device but all I get is a blank white jpg. I am using Snapshot to capture the image. I suspect that it is not working the way I expect.
Here is my code for the Save. Any insight into how to save the drawing to a file is much appreciated!

`
void OnSaveButtonClicked(object sender, EventArgs args)
{
int width = (int)canvasView.CanvasSize.Width;
int height = (int)canvasView.CanvasSize.Height;
var info = new SKImageInfo(width, height);

        var item = (FingerPaintPage)((Button)sender).BindingContext;

        using (var surface = SKSurface.Create(width, height, SKImageInfo.PlatformColorType, SKAlphaType.Premul))
        {
            SKData skData = surface.Snapshot().Encode();

            IFolder folder = FileSystem.Current.LocalStorage;
            string path = folder.Path;
            string fileout = path + "/outfile.jpg";
            string fileout2 = path + "/outfile2.jpg";

            // Plan A)
            using (Stream stream2 = File.OpenWrite(fileout))
            {
                skData.SaveTo(stream2);
            }        

            // Plan B)
            SKBitmap bitmap = new SKBitmap(width, height);
            // create an image and then get the PNG (or any other) encoded data
            using (var image = SKImage.FromBitmap(bitmap))
            using (var data = image.Encode(SKEncodedImageFormat.Jpeg, 100))
            {
                // save the data to a stream
                using (var stream = File.OpenWrite(fileout2))
                {
                    data.SaveTo(stream);
                }
            }
        }
    }`

Shell for first app?

$
0
0

Hi

In my very first app for Xamarin I need a relatively simple app UI wise with burger menu and single pages leading from burger menu options.

Is xamarin.forms shell the way to go for me?

Thanks

Regards

Master page displaying backgroundImage in iOS but not in Android Project ?

$
0
0

`<?xml version="1.0" encoding="UTF-8"?>

<MasterDetailPage.Master >

    <ContentPage BackgroundImage="overlay.png" Title="Hello" Icon="menu.png">
        <AbsoluteLayout>
            <StackLayout AbsoluteLayout.LayoutBounds="0.5,0.1,0.7,0.2" AbsoluteLayout.LayoutFlags="All">
                <Label Text="Nome do Medico" FontAttributes= "Bold" FontSize="20" TextColor="White"/>
                <Label Text="CRM 1234567890" FontSize= "15" TextColor="White"/>
            </StackLayout>
            <BoxView AbsoluteLayout.LayoutBounds="0,0.2,1,0.001" AbsoluteLayout.LayoutFlags="All" Color= "White"/>

             <StackLayout AbsoluteLayout.LayoutBounds="0.5,0.4,0.7,0.3" AbsoluteLayout.LayoutFlags="All">
                <Label Text="PERFIL" FontAttributes= "Bold" FontSize="20" TextColor="White"/>
                <Label Text="MEUS HORARIOS" FontSize= "20" TextColor="White"/>
            </StackLayout>
      <Button Image="power.png" AbsoluteLayout.LayoutBounds= "0.2,0.9,0.15,0.08" AbsoluteLayout.LayoutFlags="All" BackgroundColor= "Transparent" BorderRadius="20" />

        </AbsoluteLayout> 


    </ContentPage>
</MasterDetailPage.Master>

    <MasterDetailPage.Detail >
   <NavigationPage>
        <x:Arguments>
           <ui:DetailSixthScreen />
        </x:Arguments>
   </NavigationPage>
</MasterDetailPage.Detail>


`

Hi,
I have written a master detail page in xamarin forms. Master Page appears from left side in iOS and works good.I have set a background image in master content page and that is rendered in iOS But , this image is not rendered in Android although I have added image in resources of android project. I tried adding different images in resources (drawable_hdpi) but a blank white screen in displayed instead of backgroundimage.
Help Please

Why Xamarin.Forms project doesnt create drawable folders? Only mipmap folders?

$
0
0

When you create a new xamarin.forms project, i dont see all drawable folders? are they not used anymore? there are only mipmap folders which are only used for launcher icon i think. Earlier versions of VS 2017 was creating drawable folders in default template. Is it a bug?


Better way to get IsVisible bindings

$
0
0

Hi. I have 2 images for each object in collection view. Those objects are in collection view which is grouped. I need to show one of the images based on input. My solution what I have in my mind is to create variable in the class while creating new object and than bind the IsVisible to this variable. Is there a better way how to do this ?

Binding Source

$
0
0

Hi,

I want to set a string in another class say App.Xaml.cs

public string MyValue = "somevalue";

How can i bind the text of a label to that MyValue item? I'm not sure how the Databinding source works or how I need to wire it up.

I've tried this which didnt work...

<Label Text = {Binding MyValue, Source={x:Static local:App.MyValue}} />

I've got a static piece of text that I want to display on multiple pages so thought to put it in one place and then try and bind to that so that when I need to change it i can change it in one place.

How to display Media Picker when a user navigates to a tabbed page

$
0
0

I'm trying to display James Montemagno's Media Picker immediately when a user navigates to one of my tabbed pages. I found a function called OnAppearing() that I tried overriding to create this result. Although it technically shows the camera immediately when I switch tabs, after I close out of the media picker I get an error saying "only one operation can be active at a time".

Here is how I'm trying to implement this feature:

    protected override async void OnAppearing()
        {
            TakePhotoButton_Clicked();
        }


        async void TakePhotoButton_Clicked()
        {
            //Allows users to take pictures in the app
            if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
            {
                DisplayAlert("No Camera", "Camera is not available.", "OK");
                return;
            }

            var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
            {
                //Sets the properties of the photo file 
                SaveToAlbum = true,
                PhotoSize = PhotoSize.MaxWidthHeight,
                DefaultCamera = CameraDevice.Rear
            });

            if (file == null)
                return;
        }

I'm pretty new to all of this and I feel as if I'm making a technical error. I read this post https: //damian.fyi/2016/07/06/only-one-operation-can-be-active-at-at-time/ about someone getting the same error, but I'm not catching how I could be achieving this feature differently.

(remove the space between https: and the // because this forum wouldn't allow me to post links

vs for Mac can not develop Mac APP now?

$
0
0

Xamarin.Mac can not be developed on vs for Mac now?

create object can not find Mac App

I want to use a c++ code but I do not know c++?

$
0
0

I see a c++code and want to use it in Xamarin. but I can not re-write it to build a library.
and the c++code can not use directly it need some fix.

need I learn c++ first?

Viewing all 79144 articles
Browse latest View live


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