miércoles, 12 de julio de 2023

Xamarn forms: How to show a listview under a listview item?

https://stackoverflow.com/questions/61521479/xamarn-forms-how-to-show-a-listview-under-a-listview-item 


You can create the listview with group style ,and customize the GroupHeaderTemplate , modify the binding data when click on the group , check my sample .

XAML

<ListView x:Name ="lstView" IsGroupingEnabled="true">
    <ListView.GroupHeaderTemplate>
        <DataTemplate>
            <ViewCell>
                <Label Text="{Binding LongName}" BackgroundColor="LightBlue" >
                    <Label.GestureRecognizers>
                        <TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped"/>
                    </Label.GestureRecognizers>
                </Label>
            </ViewCell>
        </DataTemplate>
    </ListView.GroupHeaderTemplate>
    <ListView.ItemTemplate>
        <DataTemplate>
            <TextCell Text="{Binding Name}" Detail="{Binding Comment}" />
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

Model

public class VeggieModel
{
    public string Name { get; set; }
    public string Comment { get; set; }
    public bool IsReallyAVeggie { get; set; }
    public string Image { get; set; }
    public VeggieModel ()
    { }
}

public class GroupedVeggieModel : ObservableCollection<VeggieModel> 
{
    public string LongName { get; set; }
    public string ShortName { get; set; }
    public bool IsExpand { get; set; }
}

Page

public partial class GroupedListXaml : ContentPage
{
    private ObservableCollection<GroupedVeggieModel> grouped { get; set; }
    private ObservableCollection<GroupedVeggieModel> groupedCopy { get; set;  }

    public GroupedListXaml ()
    {
        InitializeComponent ();
        grouped = InitData();
        groupedCopy = InitData();

        lstView.ItemsSource = grouped;
    }

    ObservableCollection<GroupedVeggieModel> InitData()
    {
        ObservableCollection<GroupedVeggieModel> grouped = new ObservableCollection<GroupedVeggieModel>();
        GroupedVeggieModel veggieGroup = new GroupedVeggieModel() { LongName = "vegetables", ShortName = "v", IsExpand = true };
        GroupedVeggieModel fruitGroup = new GroupedVeggieModel() { LongName = "fruit", ShortName = "f", IsExpand = true };

        veggieGroup.Add(new VeggieModel() { Name = "celery", IsReallyAVeggie = true, Comment = "try ants on a log" });
        veggieGroup.Add(new VeggieModel() { Name = "tomato", IsReallyAVeggie = false, Comment = "pairs well with basil" });
        veggieGroup.Add(new VeggieModel() { Name = "zucchini", IsReallyAVeggie = true, Comment = "zucchini bread > bannana bread" });
        veggieGroup.Add(new VeggieModel() { Name = "peas", IsReallyAVeggie = true, Comment = "like peas in a pod" });
        fruitGroup.Add(new VeggieModel() { Name = "banana", IsReallyAVeggie = false, Comment = "available in chip form factor" });
        fruitGroup.Add(new VeggieModel() { Name = "strawberry", IsReallyAVeggie = false, Comment = "spring plant" });
        fruitGroup.Add(new VeggieModel() { Name = "cherry", IsReallyAVeggie = false, Comment = "topper for icecream" });
        grouped.Add(veggieGroup);
        grouped.Add(fruitGroup);
        return grouped;
    }

    void Click(GroupedVeggieModel model)
    {
        if (model.IsExpand)
        {
            var index = grouped.IndexOf(model);
            var context = groupedCopy[index];
            foreach (var m in context)
            {
                model.Add(m);
            }
        }
        else
        {
            model.Clear();
        }
    }

    private void TapGestureRecognizer_Tapped(object sender, EventArgs e)
    {
        var label = sender as Label;
        var model = label.BindingContext as GroupedVeggieModel;
        model.IsExpand = !model.IsExpand;

        Click(model);           
    }
}

enter image description here


martes, 11 de julio de 2023

Swipeable ListView in Xamarin Forms

https://www.mobmaxime.com/blog/swipeable-listview-in-xamarin-forms/

Setting up a Blank Solution

We will start by creating a Blank Forms application. We will use the Blank Forms App (Multiplatform) provided by Xamarin.

Set Your Appointments with Calendar

new-project-file

Data Class

Here is a simple data class that will hold some details about a song.

public class Item
{
public string SongName { get; set; }
public string AlbumThumbnail { get; set; }
public string SingerName { get; set; }
}

The BaseViewModel class is the extended class of INotifyPropertyChanged, to update the property & view.

BaseViewmodel

using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace SwipListViewDemo
{
    public class BaseViewModel : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
        protected void OnPropertyChanged([CallerMemberName] string propertyName = "")
        {
            var changed = PropertyChanged;
            if (changed == null)
                return;

            changed.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}

MainViewModel

We add some dummy playlist data in list-view.

using System.Collections.ObjectModel;
namespace SwipListViewDemo
{
public class MainViewModel : BaseViewModel
{
ObservableCollection<Item> _listData;
public MainViewModel()
{
BindData();
}

public ObservableCollection<Item> ListData {
get {
return _listData;
}
set {
_listData = value;
OnPropertyChanged();
}
}

private void BindData()
{
ListData = new ObservableCollection<Item>();
ListData.Add(new Item() { SongName = "Shape Of You", SingerName = "ED Sheeran", AlbumThumbnail = "https://miro.medium.com/max/2560/1*bqNsZ6GB2aMsZE20m8tcJw.jpeg" });
ListData.Add(new Item() { SongName = "Despacito", SingerName = "Luis Fonsi feat. Daddy Yankee", AlbumThumbnail = "https://i.ytimg.com/vi/x724C_mntSE/maxresdefault.jpg" });
ListData.Add(new Item() { SongName = "Bom Bidi Bom", SingerName = "Nicki Minaj", AlbumThumbnail = "https://m.media-amazon.com/images/I/810LbeBAA5L._SS500_.jpg" });
ListData.Add(new Item() { SongName = "Witness", SingerName = "Katy Perry", AlbumThumbnail = "https://www.aljazeera.com/mritems/Images/2014/10/26/04cca55fea2247b2a15d32ca7227291c_18.jpg" });
ListData.Add(new Item() { SongName = "Tsunami", SingerName = "Katy Perry", AlbumThumbnail = "https://i.ytimg.com/vi/nZ-X-dhQrvQ/maxresdefault.jpg" });
ListData.Add(new Item() { SongName = "Swish Swish", SingerName = "Katy Perry Ft Nicki Minaj", AlbumThumbnail = "https://a10.gaanacdn.com/images/song/75/21459675/crop_480x480_1534501869.jpg" });
ListData.Add(new Item() { SongName = "Greedy", SingerName = "Ariana Grande", AlbumThumbnail = "https://i.pinimg.com/originals/4f/90/91/4f90916647b1819cc3e99928086af00c.jpg" });
ListData.Add(new Item() { SongName = "I Got You", SingerName = "Bebe Rexha", AlbumThumbnail = "https://i.ytimg.com/vi/VpUgwi-9b1I/maxresdefault.jpg" });
ListData.Add(new Item() { SongName = "Wake Me Up", SingerName = "Avicii", AlbumThumbnail = "https://upload.wikimedia.org/wikipedia/en/d/da/Avicii_Wake_Me_Up_Official_Single_Cover.png" });
ListData.Add(new Item() { SongName = "BeFoUr", SingerName = "Zayn Malik", AlbumThumbnail = "https://assets.teenvogue.com/photos/56ea9853d06bfe7770d2bf32/16:9/w_1280,c_limit/12797882_1298441130172810_1723182945_n.jpg" });
ListData.Add(new Item() { SongName = "Mercy", SingerName = "Shawn Mendes", AlbumThumbnail = "https://a10.gaanacdn.com/images/song/75/21459675/crop_480x480_1534501869.jpg" });
}
}
}

Layout

We will use a ListView and SwipeView is wrapped in a DataTemplate, so it can be easily reused within the ListView.

<?xml version="1.0" encoding="utf-8"?>
<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"
    xmlns:ffimageloading="clr-namespace:FFImageLoading.Forms;assembly=FFImageLoading.Forms"
    x:Class="SwipListViewDemo.MainPage">
    <ListView
        x:Name="listView"
        HasUnevenRows="True"
        SeparatorVisibility="None"
        ItemsSource="{Binding ListData}">
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    <StackLayout
                        Spacing="0">
                        <SwipeView>
                            <SwipeView.LeftItems>
                                <SwipeItems>
                                    <SwipeItem
                                        IconImageSource="ic_heart.png"
                                        BackgroundColor="LightSeaGreen"
                                        Invoked="SwipeItem_Favorite" />
                                </SwipeItems>
                            </SwipeView.LeftItems>
                            <SwipeView.RightItems>
                                <SwipeItems>
                                    <SwipeItem
                                        IconImageSource="ic_bin.png"
                                        BackgroundColor="IndianRed"
                                        Invoked="SwipeItem_Delete" />
                                </SwipeItems>
                            </SwipeView.RightItems>
                            <!-- Content -->
                            <StackLayout
                                Spacing="10"
                                Orientation="Horizontal"
                                Padding="20,10">
                                <ffimageloading:CachedImage
                                    Source="{Binding AlbumThumbnail}"
                                    DownsampleWidth="60"
                                    DownsampleHeight="60"
                                    HeightRequest="60"
                                    WidthRequest="60"
                                    LoadingPlaceholder="ic_placeholder"
                                    ErrorPlaceholder="ic_placeholder"
                                    DownsampleToViewSize="true" />
                                <StackLayout
                                    VerticalOptions="CenterAndExpand"
                                    Spacing="5">
                                    <Label
                                        Text="{Binding SongName}"
                                        FontSize="18"
                                        TextColor="Black"/>
                                    <Label
                                        Text="{Binding SingerName}"
                                        FontSize="13"
                                        TextColor="Gray"/>
                                </StackLayout>
                            </StackLayout>
                        </SwipeView>
                        <BoxView
                            HeightRequest="1"
                            VerticalOptions="EndAndExpand"
                            BackgroundColor="Gray" />
                    </StackLayout>
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
</ContentPage>

In the code behind our MainPage, we will handle the Delete and Favorite Item Action.

using Xamarin.Forms;
namespace SwipListViewDemo
{
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
Title = "Playlist";
BindingContext = new MainViewModel();
}

void SwipeItem_Delete(System.Object sender, System.EventArgs e)
{
var selectedItem = (sender as SwipeItem).BindingContext as Item;
DisplayAlert("", selectedItem.SongName + " Deleted From PlayList", "ok");
}

void SwipeItem_Favorite(System.Object sender, System.EventArgs e)
{
var selectedItem = (sender as SwipeItem).BindingContext as Item;
DisplayAlert("", selectedItem.SongName + " Added In Favorite List", "ok");
}
}
}

That’s it! Now the ListView is not just styled, but it allows for right and left item swipe behavior with action.

Here is what the final result should like on Android and iOS :

Android:

Swipeable ListView Swipeable ListView

iOS:

Swipeable ListView Swipeable ListView

You can find the whole source-code in my Download.

jueves, 29 de junio de 2023

sql last last_execution_time

 SELECT execquery.last_execution_time AS [Date Time], execsql.text AS [Script] FROM sys.dm_exec_query_stats AS execquery

CROSS APPLY sys.dm_exec_sql_text(execquery.sql_handle) AS execsql

ORDER BY execquery.last_execution_time DESC

jueves, 22 de junio de 2023

Notepad++ cached files location

 https://stackoverflow.com/questions/29617349/notepad-cached-files-location


C:\Users\USER\AppData\Roaming\Notepad++\backup

jueves, 1 de junio de 2023

semana del la semana sql server

    SELECT DATEPART(WEEK, @FechaInicio)  -

    DATEPART(WEEK, DATEADD(MM, DATEDIFF(MM,0,@FechaInicio ), 0))+ 1 AS SemanaMes


SELECT DATEPART(ISO_WEEK, @FechaInicio) as NumSemana

jueves, 25 de mayo de 2023

Using FOR XML PATH

 https://www.sqlmatters.com/Articles/Converting%20row%20values%20in%20a%20table%20to%20a%20single%20concatenated%20string.aspx

Solution 5 : Using FOR XML PATH

Some of the XML statements introduced in SQL Server 2005 had to implement a means of looping around data in order to produce XML. This solution takes advantage of this, but strips out the XML specific parts to produce the comma separated list.
SELECT STUFF((SELECT ',' + Txt
            FROM ConcatenationDemo
            FOR XML PATH('')) ,1,1,'') AS Txt

martes, 23 de mayo de 2023

sql server separar cadenas

CREATE FUNCTION [dbo].[SepararCadena](@cadena      NVARCHAR(MAX),  

                                     @delimitador CHAR(1))  

RETURNS @output TABLE(splitData NVARCHAR(MAX))  

AS  

     BEGIN  

         DECLARE @start INT  

         DECLARE @end INT  

         SELECT @start = 1,  

                @end = CHARINDEX(@delimitador, @cadena)  

         WHILE @start < LEN(@cadena) + 1  

             BEGIN  

                 IF @end = 0  

                     SET @end = LEN(@cadena) + 1  

                 INSERT INTO @output(splitData)  

                 VALUES(SUBSTRING(@cadena, @start, @end-@start))  

                 SET @start = @end + 1  

                 SET @end = CHARINDEX(@delimitador, @cadena, @start)  

             END  

         RETURN  

     END