#region License
// // Разработано: Коротенко Владимиром Николаевичем (Vladimir N. Korotenko)
// // email: koroten@ya.ru
// // skype:vladimir-korotenko
// // https://vkorotenko.ru
// // Создано: 13.03.2020 10:35
#endregion
using SpecialForcesDirectory.Models;
using SpecialForcesDirectory.ViewModels;
using SpecialForcesDirectory.Views;
using Xamarin.Forms;
namespace SpecialForcesDirectory.Code
{
public class NotesSearchHandler : SearchHandler
{
private readonly NotesViewModel _vm = new NotesViewModel();
protected override void OnQueryChanged(string oldValue, string newValue)
{
base.OnQueryChanged(oldValue, newValue);
if (string.IsNullOrWhiteSpace(newValue))
{
ItemsSource = null;
}
else
{
_vm.SearchCommand.Execute(newValue);
ItemsSource = _vm.Items;
}
}
protected override async void OnItemSelected(object o)
{
base.OnItemSelected(o);
if (!(o is NoteItem item)) return;
if (!(Application.Current.MainPage is Shell shell)) return;
if (item.IconType == NoteItem.IconFolder)
await shell.GoToAsync($"///notes?id={item.Id}");
else
await shell.Navigation.PushAsync(new NoteEditPage(item));
}
}
}
#region License
// // Разработано: Коротенко Владимиром Николаевичем (Vladimir N. Korotenko)
// // email: koroten@ya.ru
// // skype:vladimir-korotenko
// // https://vkorotenko.ru
// // Создано: 15.03.2020 9:19
#endregion
using System;
using System.Threading.Tasks;
using SpecialForcesDirectory.Models;
using SpecialForcesDirectory.ViewModels;
using SpecialForcesDirectory.Views.Settings;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
namespace SpecialForcesDirectory.Views
{
[XamlCompilation(XamlCompilationOptions.Compile)]
[QueryProperty("PageId", "id")]
public partial class NotesPage : ContentPage
{
private readonly NotesViewModel _vm;
public NotesPage()
{
BindingContext = _vm = new NotesViewModel();
InitializeComponent();
_vm.ShowEditAction += async item => await ShowEdit(item);
}
public string PageId
{
set
{
var val = Uri.UnescapeDataString(value);
var ds = new NotesViewModel();
ds.GoToFolderCommand.Execute(new NoteItem {Id = int.Parse(val)});
BindingContext = ds;
}
}
private async Task ShowEdit(NoteItem item)
{
await Navigation.PushAsync(new NoteEditPage(item));
}
protected override void OnAppearing()
{
base.OnAppearing();
_vm.LoadItemsCommand.Execute(null);
}
private async void AddNoteClicked(object sender, EventArgs e)
{
var fullVariant = new[]
{
Resource.NotesFolderName,
Resource.NotesNoteName
};
var variants = fullVariant;
if (_vm.ParentId != 0)
variants = new[]
{
Resource.NotesNoteName
};
var cancel = Resource.NotesCancelLabel;
var variant = await DisplayActionSheet(Resource.NotesAddDialogTitle, cancel, null, variants);
if (variant == cancel) return;
var initial = Resource.NotesDialogNewNote;
if (variant == fullVariant[0])
initial = Resource.NotesDialogNewFolder;
var name = await DisplayPromptAsync(
Resource.NotesDialogTitle,
Resource.NotesDialogMessage,
Resource.DialogOK,
Resource.CloseButton,
initialValue: initial,
maxLength: 100,
keyboard: Keyboard.Text);
if (string.IsNullOrWhiteSpace(name)) return;
if (variant == fullVariant[0])
_vm.CreateFolderCommand.Execute(name);
else
_vm.CreateNoteCommand.Execute(name);
}
private async void EditClicked(object sender, EventArgs e)
{
if (MainView.SelectedItem is NoteItem item) await Navigation.PushAsync(new NoteEditPage(item));
}
private void AwayFromFolder(object sender, EventArgs e)
{
_vm.GoToRootFolder.Execute(null);
}
private async void OnSettingsClicked(object sender, EventArgs e)
{
await Navigation.PushAsync(new SettingPage());
}
}
}
<?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"
xmlns:code="clr-namespace:SpecialForcesDirectory.Code;assembly=SpecialForcesDirectory"
xmlns:controls="clr-namespace:SpecialForcesDirectory.Controls;assembly=SpecialForcesDirectory"
mc:Ignorable="d"
Title="{Binding Title}"
x:Class="SpecialForcesDirectory.Views.NotesPage"
Visual="Material">
<ContentPage.ToolbarItems>
<ToolbarItem
Text="{Binding SettingButton}"
Order="Secondary" Priority="2"
Clicked="OnSettingsClicked" />
</ContentPage.ToolbarItems>
<ContentPage.Resources>
<DataTemplate x:Key="NoteTemplate">
<SwipeView>
<Grid Padding="10">
<Grid.GestureRecognizers>
<TapGestureRecognizer
Command="{Binding Source={x:Reference MainView}, Path=BindingContext.EditCommand}"
CommandParameter="{Binding}" />
</Grid.GestureRecognizers>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="32" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Image Grid.RowSpan="2"
Source="{Binding Icon}"
HeightRequest="24"
WidthRequest="24" />
<Label Grid.Column="1" Grid.Row="0"
Text="{Binding Title }"
FontAttributes="Bold" />
<Label Grid.Row="1"
Grid.Column="1"
Text="{Binding ShortDetail }"
FontAttributes="Italic"
VerticalOptions="End" />
</Grid>
<SwipeView.RightItems>
<SwipeItems>
<SwipeItem Text="{Binding NotesDelete}"
IconImageSource="baseline_delete_outline_black_24.png"
BackgroundColor="DarkRed"
Command="{Binding Source={x:Reference MainView}, Path=BindingContext.DeleteCommand}"
CommandParameter="{Binding}" />
<SwipeItem Text="{Binding NotesEdit}"
IconImageSource="baseline_edit_black_24.png"
BackgroundColor="LightGreen"
Command="{Binding Source={x:Reference MainView}, Path=BindingContext.EditCommand}"
CommandParameter="{Binding}" />
</SwipeItems>
</SwipeView.RightItems>
</SwipeView>
</DataTemplate>
<DataTemplate x:Key="FolderTemplate">
<SwipeView>
<Grid Padding="10">
<Grid.GestureRecognizers>
<TapGestureRecognizer
Command="{Binding Source={x:Reference MainView}, Path=BindingContext.GoToFolderCommand}"
CommandParameter="{Binding}" />
</Grid.GestureRecognizers>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="32" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Image Grid.Column="0"
Source="{Binding Icon}"
HeightRequest="24"
WidthRequest="24" />
<Label Grid.Column="1" Grid.Row="0"
Text="{Binding Title }"
FontAttributes="Bold" />
</Grid>
<SwipeView.RightItems>
<SwipeItems>
<SwipeItem Text="{Binding NotesDelete}"
IconImageSource="baseline_delete_outline_black_24.png"
BackgroundColor="DarkRed"
Command="{Binding Source={x:Reference MainView}, Path=BindingContext.DeleteCommand}"
CommandParameter="{Binding}" />
<SwipeItem Text="{Binding NotesEdit}"
IconImageSource="baseline_edit_black_24.png"
BackgroundColor="LightGreen"
Command="{Binding Source={x:Reference MainView}, Path=BindingContext.EditCommand}"
CommandParameter="{Binding}" />
</SwipeItems>
</SwipeView.RightItems>
</SwipeView>
</DataTemplate>
<controls:NoteDataTemplateSelector x:Key="TemplateSelector"
NoteTemplate="{StaticResource NoteTemplate}"
FolderTemplate="{StaticResource FolderTemplate}" />
</ContentPage.Resources>
<Shell.SearchHandler>
<code:NotesSearchHandler Placeholder="{Binding NotesSearchPlaceholder}"
ShowsResults="true"
SearchBoxVisibility="Collapsible"
DisplayMemberName="Title"
Command="{Binding SearchItemSelectedCommand}"
CommandParameter="{Binding}">
<code:NotesSearchHandler.ItemTemplate>
<DataTemplate>
<Grid Padding="10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Label Grid.Column="0"
Text="{Binding Title}"
FontAttributes="Bold" />
</Grid>
</DataTemplate>
</code:NotesSearchHandler.ItemTemplate>
</code:NotesSearchHandler>
</Shell.SearchHandler>
<ContentPage.Content>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<AbsoluteLayout Grid.Row="0">
<RefreshView IsRefreshing="{Binding IsBusy, Mode=OneWay}"
Command="{Binding LoadItemsCommand}">
<CollectionView
x:Name="MainView"
AbsoluteLayout.LayoutFlags="All"
AbsoluteLayout.LayoutBounds="0,1,1,1"
SelectionMode="Single"
ItemTemplate="{StaticResource TemplateSelector}"
ItemsSource="{Binding Items}" />
</RefreshView>
<Button
AbsoluteLayout.LayoutFlags="PositionProportional"
AbsoluteLayout.LayoutBounds="1.0,1.0,-1,-1"
Text="+"
FontSize="22"
FontAttributes="Bold"
TextColor="White"
Margin="10"
HeightRequest="48"
CornerRadius="24"
BackgroundColor="{StaticResource NavigationPrimary}"
Clicked="AddNoteClicked"
WidthRequest="48" />
</AbsoluteLayout>
</Grid>
</ContentPage.Content>
</ContentPage>
а что вам нужно?
Подключаете эту библиотеку к странице, получаете qr