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

Xamarin Forms - Epub: System.AggregateException: One or more errors occurred

$
0
0

I am converting my epub file URL to stream and saving to local DB as bytes like below:

Stream stream;
HttpClient client = new HttpClient();
var response = await client.GetAsync(fileUrl);
stream = await response.Content.ReadAsStreamAsync();
epubBook = EpubReader.ReadBook(stream);

//saving to folder
byte[] bytes = await response.Content.ReadAsByteArrayAsync();
string filename = Path.GetFileName(fileUrl);
var folderPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
var filePath = Path.Combine(folderPath, filename);
File.WriteAllBytes(filePath, bytes);

This is working fine for most of the files. But some file URLs showing System.AggregateException.

Exception Details

System.AggregateException: One or more errors occurred. (Version number '1.1' is invalid. Line 1, position 16.) ---> System.Xml.XmlException: Version number '1.1' is invalid. Line 1, position 16.
at System.Xml.XmlTextReaderImpl.Throw (System.Exception e) [0x00027] in <0757e7484a1349cca3b4558c721885b2>:0
at System.Xml.XmlTextReaderImpl.Throw (System.String res, System.String arg) [0x00029] in <0757e7484a1349cca3b4558c721885b2>:0
at System.Xml.XmlTextReaderImpl.ParseXmlDeclaration (System.Boolean isTextDecl) [0x0061f] in <0757e7484a1349cca3b4558c721885b2>:0
at System.Xml.XmlTextReaderImpl.Read () [0x000c6] in <0757e7484a1349cca3b4558c721885b2>:0
at System.Xml.Linq.XDocument.Load (System.Xml.XmlReader reader, System.Xml.Linq.LoadOptions options) [0x00016] in <89374192b20a41739cf7c5bb822846fe>:0
at System.Xml.Linq.XDocument.Load (System.IO.Stream stream, System.Xml.Linq.LoadOptions options) [0x0000f] in <89374192b20a41739cf7c5bb822846fe>:0
at System.Xml.Linq.XDocument.Load (System.IO.Stream stream) [0x00000] in <89374192b20a41739cf7c5bb822846fe>:0
at VersOne.Epub.Internal.XmlUtils+<>c__DisplayClass0_0.b__0 () [0x00000] in <7c46dbfe3ebf403389304a938822832e>:0
at System.Threading.Tasks.Task`1[TResult].InnerInvoke () [0x0000f] in <46c2fa109b574c7ea6739f9fe2350976>:0
at System.Threading.Tasks.Task.Execute () [0x00000] in <46c2fa109b574c7ea6739f9fe2350976>:0

--- End of stack trace from previous location where exception was thrown ---

Sample file URLs having this issue:

https://s3.us-east-1.amazonaws.com/catholic-brain/prod/dc/cbrain-app/files/doc-lib/2020/08/10/12/56/42/068/head/9781612781495_EPUB.epub

https://s3.us-east-1.amazonaws.com/catholic-brain/prod/dc/cbrain-app/files/doc-lib/2020/08/10/07/36/06/376/head/9781612781358_EPUB.epub

I am using EpubReader.Cross Nuget for parsing the epub file.


How to add Additional mtouch arguments?

$
0
0

Hello,
I need to add two additional arguments under --optimize in "Additional mtouch arguments" for iOS...how do I do it?

  • Option A: --optimize=-remove-dynamic-registrar --optimize=experimental-xforms-product-type
  • Option B: --optimize=-remove-dynamic-registrar,experimental-xforms-product-type

Which one is correct, if any? Thanks

How to disable the verticalscrolling of the shell flyout

$
0
0
I tryed to xaml - msft doc- <Shell
FlyoutVerticalScrollMode="Disabled"> also code behind Shell.Current.FlyoutVerticalScrollMode = ScrollMode.Disabled ,vertical scrolling is not disableing,

Can I use Immersive in Xamarin.Forms Shell?

$
0
0

It seems that it is not work in Shell not in ContentPage?

UWP Setting Custom Icon in MapRenderer

$
0
0

I'm trying to draw text on a custom image and set it as a map icon. I've done this with Android and IoS; however, in UWP I've encountered some issues.
The UWP renderer mapIcon.Image requires a uri, stream or file. I've tried several different ways. The following is attempting to return a stream:

public async Task WriteTextOnImage(string uri, string text, Windows.UI.Color color)
{
Uri uriSource = new Uri(uri);
using (CanvasBitmap bitmap = await CanvasBitmap.LoadAsync(CanvasDevice.GetSharedDevice(), uriSource).AsTask().ConfigureAwait(false))
using (CanvasRenderTarget target = new CanvasRenderTarget(CanvasDevice.GetSharedDevice(), (float)bitmap.Size.Width, (float)bitmap.Size.Height, bitmap.Dpi))
{
using (var ds = target.CreateDrawingSession())
{
ds.Clear(Colors.White);
ds.DrawImage(bitmap);
ds.DrawText(text, new System.Numerics.Vector2(150, 150), color);
}
byte[] arr = target.GetPixelBytes();
MemoryStream stream = new MemoryStream(arr);
return stream.AsRandomAccessStream();
}
}

The image is not appearing. I'd appreciate any ideas on this issue.

ZXing - defining scanning area

$
0
0

Hi everyone,
can I define scanning area in ZXing.Net.Mobile? I would like to scaned only center of screen.
I using ZXingScannerView and ZXingDefaultOverlay.

<zxing:ZXingScannerView Options="{Binding ScannerOptions}" IsScanning="{Binding IsScanning}" IsAnalyzing="{Binding IsAnalyzing}" IsEnabled="True" IsTorchOn="{Binding TorchOn, Mode=TwoWay}" Result="{Binding Result, Mode=TwoWay}" ScanResultCommand="{Binding ScanCommand}" /> <zxing:ZXingDefaultOverlay Opacity="0.9" />

Always keep on keyboard in android on focus to next Entry.

$
0
0

I am having 20 entries and these are created dynamically through loop. and on textchanges i have set focus to the next entry ,having focus to next entry keyboard hides and than show again and it happen on every text change.I want that keyboard should not hide every time after textchange it show always show till the last 20th entry..

----My Custom Entry

public class MyEntry : Entry
{

    public static readonly BindableProperty IsFocusProperty = BindableProperty.Create("IsFocus", typeof(bool), typeof(MyEntry), false, propertyChanged: OnChanged);

    static void OnChanged(BindableObject bindable, object oldValue, object newValue)
    {
        var entry = bindable as MyEntry;

        var focus = (bool)newValue;

        if (focus)
        {
            entry.Focus();
        }
        else
        {
            entry.Unfocus();
        }

    }

    public bool IsFocus
    {
        get { return (bool)GetValue(IsFocusProperty); }
        set
        {
            SetValue(IsFocusProperty, value);
        }
    }

    public MyEntry()
    {
        this.Focused += MyEntry_Focused;
        this.Unfocused += MyEntry_Unfocused;
    }

    private void MyEntry_Unfocused(object sender, FocusEventArgs e)
    {
        this.IsFocus = false;
    }

    private void MyEntry_Focused(object sender, FocusEventArgs e)
    {
        this.IsFocus = true;
    }
   }

--My model

public  class CrossingUIModel : BaseViewModel
  {

    public int Id { get; set; }

    private string fieldValue;
    public string FieldValue
    {
        get { return fieldValue; }
        set
        {
            if (fieldValue != value)
            {
                fieldValue = value;
                OnPropertyChanged(nameof(FieldValue));
            }

        }
    }


    private bool isFocus = false;
    public bool IsFocus
    {
        get { return isFocus; }
        set
        {
            if (isFocus != value)
            {
                isFocus = value;
                OnPropertyChanged(nameof(IsFocus));
            }

        }
    }




}

--my View Model

    public void CreateUI()
    {
        UserDialogs.Instance.ShowLoading();

        BindCrossingUIModel = new ObservableCollection<CrossingUIModel>();

        for (int i = 1; i < 21; i++)
        {
            CrossingUIModel model = new CrossingUIModel();
            model.Id = i;
            BindCrossingUIModel.Add(model);
        }

        foreach (CrossingUIModel model in BindCrossingUIModel)
        {
            model.PropertyChanged += Model_PropertyChanged;
        }

        UserDialogs.Instance.HideLoading();

    }

    private void Model_PropertyChanged(object sender, PropertyChangedEventArgs e)
    {
        if (e.PropertyName == "FieldValue")
        {
            var model = sender as CrossingUIModel;

            if (model.FieldValue.Length == 1)
            {
                model.FieldValue = model.FieldValue.Substring(0, 1);
                model.IsFocus = false;
                int id = model.Id;

                if (id == 20)
                {
                    var FocusControl = _page.FindByName<Entry>("Amt");

                    if (FocusControl != null)
                    {
                        FocusControl.Focus();
                    }

                }
                else
                {
                    BindCrossingUIModel[id].IsFocus = true;

                }
            }

        }
    }

--xaml file

          <StackLayout Grid.Row="0">
                 <CollectionView x:Name="CrossingView" ItemsSource="{Binding BindCrossingUIModel, Mode=TwoWay}" SelectionMode="Multiple">
                     <CollectionView.ItemsLayout>
                        <GridItemsLayout Orientation="Vertical"  Span="10" />
                    </CollectionView.ItemsLayout>

                    <CollectionView.ItemTemplate>
                        <DataTemplate>

                            <StackLayout WidthRequest="100"  HorizontalOptions="FillAndExpand" >
                                   <local:MyEntry WidthRequest="80" BackgroundColor="White" HeightRequest="50" 
                                               x:Name="Fields" Text="{Binding FieldValue, Mode=TwoWay}" 
                                               IsFocus="{Binding IsFocus, Mode=TwoWay}"
                                               ReturnType="Next"  Keyboard="Numeric" MaxLength="1"

                                 </StackLayout>
                            </DataTemplate>
                       </CollectionView.ItemTemplate>
                   </CollectionView>
                </StackLayout>

Xamarin forms: NoClassDefFoundError Landroidx/appcompat/app/AppCompatActivity

$
0
0

Hi guys, I'm trying to use a native android library called "ImageCropper" available here: https://github.com/ArthurHub/Android-Image-Cropper

I created android bindings, but when I try to consume it from XF custom rendered, it throws an error saying: "java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/appcompat/app/AppCompatActivity"

I'm compiling my XF app with the target version set to API 29. Not sure what I'm missing or how would I proceed to fix this issue. Any suggestions are heartily appreciated. Thanks.

In the readme of android library repo, it is mentioned that:

**Add this line to your Proguard config file

-keep class androidx.appcompat.widget.** { *; }
**
I'm not sure how would I do this in XF.

XF custom renderer: https://pastebin.com/85Mdsy8c


How to set a different color for statusBar and navBar

$
0
0

Hello everyone,

Here is a screenshot of what I'm trying to achieve.

Right now, I've a generic style which set both background and foreground color. Something like this

<Style TargetType="NavigationPage">
   <Setter Property="BarBackgroundColor" Value="{StaticResource MyBackgroundColor}" />
   <Setter Property="BarTextColor" Value="{StaticResource MyForegroundColor}" />
</Style>

It works great but I'd like to have a different status bar color than the navbar color. Is it possible from Xamarin Forms ?
If it's not, did anyone already do that with custom renderer and is willing to help me with a link or some code ?

Thanks !! Have all a good day

Music

$
0
0

How do I play audio in my app? I want the music to be on immediately after starting the application.

Show Border in Grid (Xaml)

$
0
0

I have problem with showing Border of grid in xaml.
I have Xaml page like this:

                                <?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="DAC_Check.Views.HistoryPage" BackgroundColor="White">

                                  <ContentPage.Content >
                                    <ListView    CachingStrategy="RecycleElement"
                                           SeparatorColor="Transparent"
                                           HasUnevenRows="True"
                                           x:Name="ListViewNews">
                                      <ListView.ItemTemplate>
                                        <DataTemplate>
                                          <ViewCell>
                                            **<Border BorderBrush="Black" BorderThickness="2">**
                                              <Grid ShowGridLines="True" Padding="3">
                                                <Grid.ColumnDefinitions>
                                                  <ColumnDefinition Width="55"/>
                                                  <ColumnDefinition Width="*"/>
                                                </Grid.ColumnDefinitions>

                                                <Image Source="{Binding IMG}" VerticalOptions="Center">
                                                  <Image.WidthRequest>
                                                    <OnPlatform x:TypeArguments="x:Double">
                                                      <OnPlatform.iOS>55</OnPlatform.iOS>
                                                      <OnPlatform.Android>55 </OnPlatform.Android>
                                                      <OnPlatform.WinPhone>75</OnPlatform.WinPhone>
                                                    </OnPlatform>
                                                  </Image.WidthRequest>
                                                  <Image.HeightRequest>
                                                    <OnPlatform x:TypeArguments="x:Double">
                                                      <OnPlatform.iOS>50</OnPlatform.iOS>
                                                      <OnPlatform.Android>50</OnPlatform.Android>
                                                      <OnPlatform.WinPhone>65</OnPlatform.WinPhone>
                                                    </OnPlatform>
                                                  </Image.HeightRequest>
                                                </Image>
                                                <StackLayout Grid.Column="1"
                                                             Padding="4"
                                                             Spacing="4"
                                                             VerticalOptions="Center">
                                                  <Label Text="{Binding Title}" Font="Bold,13" TextColor="Black" />
                                                  <Label Text="{Binding PublicDate}" x:Name="lbDate" FontSize="Small" LineBreakMode="WordWrap"/>
                                                  <Label/>
                                                </StackLayout>
                                              </Grid>
                                            </Border>
                                          </ViewCell>
                                        </DataTemplate>
                                      </ListView.ItemTemplate>
                                    </ListView>
                                  </ContentPage.Content>
                                </ContentPage>

When run it, the debug show that:

Xamarin.Forms.Xaml.XamlParseException: Position 14:14. Type Border not found in xmlns http://xamarin.com/schemas/2014/forms

How can i fix that???

Bluetooth Bonded devices is not working in xamarin forms

$
0
0

I am binding a list with Bluetooth Bonded devices and before it I am enabling Bluetooth with my codes. But the problem is that it is not working first time, it is working on 2nd time of my search button click. Also when I am first enabling the Bluetooth manually from the setting and then click on search button it is also working. The main miracle is that when I am using breakpoint on the method and go with step by step than it is working. Till last day it was Woking fine but what happen now it is not working. I am sharing my code. Thanks for help...

///interface class

 public interface IBlueToothService
{
  public ObservableCollection<string> GetDeviceList();
  public  Task Print(string deviceName, string text);

}

//native android dependency class

   [assembly: Xamarin.Forms.Dependency(typeof(AndroidBlueToothService))]
   namespace R1Soft_App.Droid.DependencyServices
  {
class AndroidBlueToothService : IBlueToothService
{


    public ObservableCollection<string> GetDeviceList()
    {
        using (BluetoothAdapter bluetoothAdapter = BluetoothAdapter.DefaultAdapter)
        {
            if (bluetoothAdapter.IsEnabled == false)
            {
                bluetoothAdapter.Enable();
            }

            var btdevice = bluetoothAdapter?.BondedDevices.Select(i => i.Name).OrderBy(x => 
         x).ToList();

            return new ObservableCollection <string>(btdevice);
        }
    }


    public async Task Print(string deviceName, string text)
    {
        UserDialogs.Instance.ShowLoading();

        using (BluetoothAdapter bluetoothAdapter = BluetoothAdapter.DefaultAdapter)
        {
            if (bluetoothAdapter.IsEnabled == false)
            {
                bluetoothAdapter.Enable();
            }
            BluetoothDevice device = (from bd in bluetoothAdapter?.BondedDevices
                                      where bd?.Name == deviceName
                                      select bd).FirstOrDefault();              
            try
            {
                using (BluetoothSocket bluetoothSocket = device?.
                    CreateRfcommSocketToServiceRecord(
                    UUID.FromString("00001101-0000-1000-8000-00805f9b34fb")))
                {
                    bluetoothSocket?.Connect();
                    byte[] buffer = Encoding.UTF8.GetBytes(text);
                    bluetoothSocket?.OutputStream.Write(buffer, 0, buffer.Length);
                    bluetoothSocket.Close();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            UserDialogs.Instance.HideLoading();

        }
    }
}

}

//view model code

    private readonly IBlueToothService blueToothService;

    public AddPrinterViewModel()
    {
        try
        {

            blueToothService = DependencyService.Get<IBlueToothService>();             
        } 
        catch(Exception ex)
        {
             App.Current.MainPage.DisplayAlert("Alert", ex.Message.ToString(), "Ok");
        }

    }

   public ObservableCollection<string> deviceList = new ObservableCollection<string>();
    public ObservableCollection<string> DeviceList
    {
        get
        {
            return deviceList;
        }
        set
        {
            deviceList = value;
            OnPropertyChanged(nameof(DeviceList));
        }
    }


    private Command searchCommand;
    public  Command SearchCommand
    {
        get { return searchCommand ?? (searchCommand = new Command(() =>  ExecuteSearchCommand())); }
    }

    public async void ExecuteSearchCommand()
    {

        try
        {    
            var list = blueToothService.GetDeviceList();
            DeviceList = list;             
        }

        catch (Exception ex)
        {
           await  App.Current.MainPage.DisplayAlert("Alert", ex.Message.ToString(), "Ok");
        }
        UserDialogs.Instance.HideLoading();


    }

Reset Picker with no value

$
0
0

Have a Picker with some value , how do i reset the Picker with no value when i want to use it again .

After selecting an item a listview is filled and the Picker Isvisible is false.

But what do i change to start with the Title "Kies een team ↓ " like the first time

 <Picker x:Name="picker"

        Title="Kies een team ↓ "
        TitleColor="{AppThemeBinding Light=Black, Dark=White}" FontSize="Medium" BackgroundColor="Transparent" SelectedIndexChanged="picker_SelectedIndexChanged" AbsoluteLayout.LayoutBounds=".5,.25,.70,.15" AbsoluteLayout.LayoutFlags="All" HorizontalOptions="Center" >
                                <Picker.ItemsSource>
                                    <x:Array Type="{x:Type x:String}">
                                        <x:String>1e elftal</x:String>
                                        <x:String>2e elftal</x:String>
                                        <x:String>JO16-1</x:String>
                                        <x:String>JO15-1</x:String>
                                        <x:String>JO13</x:String>
                                        <x:String>JO11</x:String>
                                        <x:String>JO10</x:String>
                                        <x:String>JO7</x:String>
                                    </x:Array>
                                </Picker.ItemsSource>
                            </Picker>

 async void mysub()
        {
            Selecteer.Text = picker.SelectedItem.ToString();
            picker.IsVisible = false;

     ///// fill a Listview with the Text depending on Selecteer.Text 

}

To start again

  picker.IsVisible = true;

Tabbedpage how to create shadow line under tabs?

$
0
0

Tabbedpage how to create shadow line under tabs?

Get started with xamarin and Azure


ZXing.Net.Mobile (Xamarin.Forms/Android) Scan on different pages do not reaktivate scanner

$
0
0

I have implemented a Xamarin.Forms App focused on Android which should scan barcodes on different pages. (Followed this description ‚https://blog.xamarin.com/barcode-scanning-made-easy-with-zxing-net-for-xamarin-forms/‘ (Thanks! James Montemagno))

I initialize the scanner control (defined in xaml) in the constructor of the codebehind class:

    <ContentPage.Content>
        <AbsoluteLayout>
            <AbsoluteLayout.Children>
                <z:ZXingScannerView
                    x:Name="zScanner"
                    AbsoluteLayout.LayoutBounds="0.5,0.5,1,1"
                    AbsoluteLayout.LayoutFlags="All"
                    HorizontalOptions="FillAndExpand"
                    IsScanning="True"                    
                    OnScanResult="ZScanner_OnOnScanResult"
                    VerticalOptions="FillAndExpand" />
                <z:ZXingDefaultOverlay
                    x:Name="zOverlay"
                    ShowFlashButton="False"
                    AbsoluteLayout.LayoutBounds="0.5,0.5,1,1"
                    AbsoluteLayout.LayoutFlags="All"
                    HorizontalOptions="FillAndExpand"
                    VerticalOptions="FillAndExpand" />
….

For embedding into the own page layout I use the ZXingScannerView-Control.

    public TicketScan()
     {
         InitializeComponent();

         // https://components.xamarin.com/gettingstarted/zxing.net.mobile.forms
         // https://blog.xamarin.com/barcode-scanning-made-easy-with-zxing-net-for-xamarin-forms/
         var zXingOptions = new MobileBarcodeScanningOptions()
         {
             DelayBetweenContinuousScans = 1000, // msec
             UseFrontCameraIfAvailable = false,
             PossibleFormats = new List<BarcodeFormat>(new[]
             {
                 BarcodeFormat.EAN_8,
                 BarcodeFormat.EAN_13,
                 BarcodeFormat.CODE_128,
                 BarcodeFormat.QR_CODE
             }),
             TryHarder = true //Gets or sets a flag which cause a deeper look into the bitmap.
         };
         zScanner.Options = zXingOptions;

         // https://github.com/Redth/ZXing.Net.Mobile/issues/427
         zOverlay.BindingContext = zOverlay;

         fab.Clicked = OnClick_AddFabButton;
    }

The first scan page works as expected.
When I leave the page I pause the scanner here:

    protected override void OnDisappearing()
    {
        base.OnDisappearing();
        zScanner.IsScanning = false;
    }

(Otherwise the scanner will scan on each further page even if no scanner control is on the page (?!) And the camera works all the time.)
On a second page I try to initialize the scanner on the same way and set IsScanning = true.

        protected override void OnAppearing()
        {
            zScanner.IsScanning = true;
            base.OnAppearing();
        }

But on this second page I see only a frozen camera picture (maybe the last shot from the first usage)
How can I use the ZXing scanner component for Xamarin.Forms on different pages without turned on camera for the whole camera usage?
thx

Tabbedpage how to create shadow line under tabs?

$
0
0

Tabbedpage how to create shadow line under tabs?

Is there a way that the keypad doesn’t get disappeared while doing entry on the screen of smartphone

$
0
0

While on a screen with the keypad open on a smartphone, when i click on something other than entry on that screen the keypad disappears, is there a way to fix this problem ?

How to Set FLAG_ACTIVITY_NEW_TASK in Android MainActivity

$
0
0

Hi All,

When try to call Activity from outside of MainActivity, then i got this error. IS

Android.Util.AndroidRuntimeException: 'Calling startActivity() from outside of an Activity context requires the FLAG_ACTIVITY_NEW_TASK flag. Is this really what you want?'

I couldn't set FLAG_ACTIVITY_NEW_TASK under Intent.

Thanks in Advance.:)

Animate labels for 20 seconds

$
0
0

I have 3 labels binded like following

<StackLayout>

<Label Padding="1" Text="VRN"  FontSize="25" TextColor="Black"  VerticalOptions="Center" HorizontalTextAlignment="Center"/> 

<Label Padding="1"  Text="{Binding VRN}" TextColor="#ba000d" FontSize="100" FontAttributes="Bold" VerticalOptions="Center" HorizontalTextAlignment="Center"/>

<Label  Padding="1" Text="Make" FontSize="25" TextColor="Black"  VerticalOptions="Center" HorizontalTextAlignment="Center"/>

 <Label Text="{Binding Make}" TextColor="#ba000d" FontSize="100" FontAttributes="Bold" VerticalOptions="Center" HorizontalTextAlignment="Center"/>

  <Label Text="{Binding Model}" TextColor="#ba000d" FontSize="30" FontAttributes="Bold" VerticalOptions="Center" HorizontalTextAlignment="Center"/>

</StackLayout>

Binding is done in ItemModel like following

string _vrn = "";
        public string VRN
        {
            protected set
            {
                if (_vrn != value)
                {
                    _vrn = value;
                    OnPropertyChanged("VRN");
                }
            }
            get { return _vrn ; }
        }
        string _make= "";
        public string Make
        {
            protected set
            {
                if (_make!= value)
                {
                    _make= value;
                    OnPropertyChanged("Make");
                }
            }
            get { return _make; }
        }
        string _model = "";
        public string Model
        {
            protected set
            {
                if (_model != value)
                {
                    _model = value;
                    OnPropertyChanged("Model");
                }
            }
            get { return _model ; }
        }
           hubConnection.On<string>("NewItem", (item) =>
            {
                MainThread.BeginInvokeOnMainThread(async () =>
                {

                        Item newItem = JsonConvert.DeserializeObject<Item>(item);    
                        VRN= newItem.VRN;
                        Make= newItem.Make;
                        Model= newItem.Model;
                 }
               }

Above code will set the labels with value of last item inserted. Up to here done.

I want to animate(Blink) the 3 labels for 20 seconds whenever new item is added to Item ObservableCollection(I am using SignalR to insert data)

I already have a class which i am using it with CollectionView for another scenario.Is there any way i can use the following class to animate Labels or is there any other easy way?

public class BlinkTriggerAction : TriggerAction<VisualElement>
{
    protected async override void Invoke(VisualElement sender)
    {
            var parentAnimation = new Animation();
            var fadeOutAnimation = new Animation(d => sender.Opacity = d, 1, 0, Easing.Linear);
            var fadeInAnimation = new Animation(d => sender.Opacity = d, 0, 1, Easing.Linear);
            parentAnimation.Add(0, 0.5, fadeOutAnimation);
            parentAnimation.Add(0.5, 1, fadeInAnimation);
            parentAnimation.Add(0, 0.5, fadeOutAnimation);
            parentAnimation.Add(0.5, 1, fadeInAnimation);
            parentAnimation.Add(0, 0.5, fadeOutAnimation);
            parentAnimation.Add(0.5, 1, fadeInAnimation);
            parentAnimation.Add(0, 0.5, fadeOutAnimation);
            parentAnimation.Add(0.5, 1, fadeInAnimation);
            parentAnimation.Commit(sender, "BlinkingVisualElement", 16, 800, repeat: () => true);
            await Task.Delay(20000);
            parentAnimation.Add(0, 0.5, fadeOutAnimation);
            parentAnimation.Add(0.5, 1, fadeInAnimation);
            sender.AbortAnimation("BlinkingVisualElement");

    }
}
Viewing all 79144 articles
Browse latest View live


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