Advertisement
eduardogr

Untitled

Dec 26th, 2019
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 11.05 KB | None | 0 0
  1. XAML
  2. ----------------------------------------------------------------------
  3. <Page x:Name="Main"
  4.       x:Class="uwpEvernote.View.NotesPage"
  5.       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  6.       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  7.       xmlns:local="using:uwpEvernote.View"
  8.       xmlns:vm="using:uwpEvernote.ViewModel"
  9.       xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  10.       xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  11.       mc:Ignorable="d"
  12.       Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
  13.  
  14.     <Page.Resources>
  15.         <vm:NotesVM x:Key="VM" />
  16.         <SolidColorBrush x:Key="enabled"
  17.                          Color="#0078D4" />
  18.         <SolidColorBrush x:Key="disabled"
  19.                          Color="Transparent" />
  20.     </Page.Resources>
  21.  
  22.     <RelativePanel x:Name="Container"
  23.                    DataContext="{StaticResource VM}">
  24.         <RelativePanel.Background>
  25.             <SolidColorBrush Color="{ThemeResource SystemRevealListMediumColor}" />
  26.         </RelativePanel.Background>
  27.         <MenuBar x:Name="menuBar">
  28.             <MenuBarItem Title="File">
  29.                 <MenuFlyoutItem Text="New notebook"
  30.                                 Command="{Binding NewNotebookCommand}">
  31.                     <MenuFlyoutItem.Icon>
  32.                         <FontIcon Glyph="&#xE82D;" />
  33.                     </MenuFlyoutItem.Icon>
  34.                 </MenuFlyoutItem>
  35.                 <MenuFlyoutItem Text="New Note"
  36.                                 Command="{Binding NewNoteCommand}"
  37.                                 CommandParameter="{Binding SelectedNotebook}">
  38.                     <MenuFlyoutItem.Icon>
  39.                         <FontIcon Glyph="&#xE70B;" />
  40.                     </MenuFlyoutItem.Icon>
  41.                 </MenuFlyoutItem>
  42.                 <MenuFlyoutSeparator />
  43.                 <MenuFlyoutItem Text="Exit"
  44.                                 Command="{Binding ExitCommand}">
  45.                     <MenuFlyoutItem.Icon>
  46.                         <FontIcon Glyph="&#xE106;" />
  47.                     </MenuFlyoutItem.Icon>
  48.                 </MenuFlyoutItem>
  49.             </MenuBarItem>
  50.  
  51.         </MenuBar>
  52.         <ListView x:Name="Notebook"
  53.                   RelativePanel.Below="menuBar"
  54.                   Width="140"
  55.                   SelectedItem="{Binding SelectedNotebook, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
  56.                   ItemsSource="{Binding NoteBooks}"
  57.                   RelativePanel.AlignBottomWithPanel="True">
  58.             <ListView.ItemTemplate>
  59.                 <DataTemplate>
  60.                     <TextBlock Text="{Binding Name}" />
  61.                 </DataTemplate>
  62.             </ListView.ItemTemplate>
  63.         </ListView>
  64.         <ListView x:Name="Notes"
  65.                   Width="140"
  66.                   ItemsSource="{Binding Notes}"
  67.                   RelativePanel.Below="menuBar"
  68.                   RelativePanel.RightOf="Notebook"
  69.                   RelativePanel.AlignBottomWithPanel="True">
  70.             <ListView.ItemTemplate>
  71.                 <DataTemplate>
  72.                     <TextBlock Text="{Binding Title}" />
  73.                 </DataTemplate>
  74.             </ListView.ItemTemplate>
  75.         </ListView>
  76.         <CommandBar x:Name="commandBar"
  77.                     RelativePanel.Below="menuBar"
  78.                     RelativePanel.RightOf="Notes"
  79.                     RelativePanel.AlignRightWithPanel="True"
  80.                     OverflowButtonVisibility="Collapsed"
  81.                     VerticalAlignment="Center"
  82.                     Margin="0,10,20,10"
  83.                     Background="{ThemeResource ButtonBackgroundThemeBrush}">
  84.             <CommandBar.Content>
  85.                 <StackPanel Orientation="Horizontal">
  86.                     <AppBarButton x:Name="textToSpeech"
  87.                                   Icon="Microphone"
  88.                                   Click="Actions_Click"
  89.                                   Tag="0"
  90.                                   ToolTipService.ToolTip="Text to speech" />
  91.                     <AppBarButton x:Name="playBtn"
  92.                                   Icon="Play"
  93.                                   Click="Actions_Click"
  94.                                   Tag="5"
  95.                                   ToolTipService.ToolTip="Read" />
  96.                     <AppBarButton x:Name="FormatBoltText"
  97.                                   ToolTipService.ToolTip="Bold"
  98.                                   Icon="Bold"
  99.                                   Tag="1"
  100.                                   Click="Actions_Click" />
  101.                     <AppBarButton x:Name="formatItalicText"
  102.                                   ToolTipService.ToolTip="Italic"
  103.                                   Icon="Italic"
  104.                                   Tag="2"
  105.                                   Click="Actions_Click" />
  106.                     <AppBarButton x:Name="formatUnderlineText"
  107.                                   ToolTipService.ToolTip="Underline"
  108.                                   Icon="Underline"
  109.                                   Tag="3"
  110.                                   Click="Actions_Click" />
  111.                     <AppBarSeparator />
  112.                     <ComboBox IsEditable="True"
  113.                               Tag="1"
  114.                               ItemsSource="{Binding Fonts}"
  115.                               Loaded="fontBox_Loaded"
  116.                               x:Name="fontBox"
  117.                               SelectionChanged="ComboChanged"
  118.                               Width="150"
  119.                               TextSubmitted="fontBox_TextSubmitted"
  120.                               />
  121.                     <ComboBox x:Name="fontSizeBox"
  122.                               ItemsSource="{Binding FontsSize}"
  123.                               Tag="2"
  124.                               TextSubmitted="fontBox_TextSubmitted"
  125.                               SelectionChanged="ComboChanged"
  126.                               IsEditable="True"
  127.                               Margin="10,0,0,0" />
  128.  
  129.                 </StackPanel>
  130.  
  131.             </CommandBar.Content>
  132.  
  133.         </CommandBar>
  134.         <Canvas x:Name="recognitionCanvas"
  135.                 Visibility="Collapsed"
  136.                 RelativePanel.RightOf="Notes"
  137.                 RelativePanel.Below="commandBar"
  138.                 RelativePanel.AlignRightWithPanel="True"
  139.                 RelativePanel.AlignBottomWith="Notebook"
  140.                 Margin="0,0,10,40" />
  141.         <InkCanvas x:Name="drawingCanvas"
  142.                    Visibility="Collapsed"
  143.                    RelativePanel.RightOf="Notes"
  144.                    RelativePanel.Below="commandBar"
  145.                    RelativePanel.AlignRightWithPanel="True"
  146.                    RelativePanel.AlignBottomWith="Notebook"
  147.                    Margin="0,0,10,40" />
  148.         <RichEditBox x:Name="richEbitBox"
  149.                      IsHandwritingViewEnabled="False"
  150.                      TextChanged="Cotent_TextChanged"
  151.                      RelativePanel.RightOf="Notes"
  152.                      RelativePanel.Below="commandBar"
  153.                      RelativePanel.AlignRightWithPanel="True"
  154.                      RelativePanel.AlignBottomWith="Notebook"
  155.                      Margin="0,0,10,40" />
  156.         <CommandBar RelativePanel.RightOf="Notes"
  157.                     RelativePanel.AlignBottomWith="richEbitBox"
  158.                     RelativePanel.AlignRightWithPanel="True"
  159.                     Margin="0,0,10,0"
  160.                     HorizontalAlignment="Left"
  161.                     VerticalAlignment="Center">
  162.             <CommandBar.Content>
  163.                 <TextBlock x:Name="charactersCount"/>
  164.             </CommandBar.Content>
  165.         </CommandBar>
  166.     </RelativePanel>
  167. </Page>
  168.  
  169. NotesViewModel
  170. ------------------------------------------------------
  171.  
  172. using Microsoft.Graphics.Canvas.Text;
  173. using SQLite;
  174. using System;
  175. using System.Collections.ObjectModel;
  176. using System.ComponentModel;
  177.  
  178. using uwpEvernote.Model;
  179. using Windows.UI.Xaml.Controls;
  180.  
  181. namespace uwpEvernote.ViewModel {
  182.     public class NotesVM: INotifyPropertyChanged {
  183.  
  184.         public ObservableCollection<NoteBook> NoteBooks { get; set; }
  185.  
  186.         private NoteBook _SelectedNotebook;
  187.  
  188.         public NoteBook SelectedNotebook {
  189.             get { return _SelectedNotebook; }
  190.             set {
  191.                 if (value != _SelectedNotebook) {
  192.                     _SelectedNotebook = value;
  193.                     //OnPropertyChanged("SelectedNotebook");
  194.                 }
  195.             }
  196.         }
  197.  
  198.         public int[] FontsSize { get; set; }
  199.         public string[] Fonts { get; set; }
  200.         public ObservableCollection<Note> Notes { get; set; }
  201.         public NewNoteCommand NewNoteCommand { get; set; }
  202.         public NewNotebookCommand NewNotebookCommand { get; set; }
  203.         public ExitCommand ExitCommand { get; set; }
  204.  
  205.  
  206.         public NotesVM() {
  207.  
  208.             NewNoteCommand = new NewNoteCommand(this);
  209.             NewNotebookCommand = new NewNotebookCommand(this);
  210.             ExitCommand = new ExitCommand(this);
  211.             NoteBooks = new ObservableCollection<NoteBook>();
  212.             Notes = new ObservableCollection<Note>();
  213.             Fonts = new string [CanvasTextFormat.GetSystemFontFamilies().Length];
  214.             FontsSize = new int[] {14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,31,31,32,33,34,35,36,37,38,39,40};
  215.             Fill();
  216.             ReadNotebooks();
  217.         }
  218.  
  219.         public void CreateNotebook() {
  220.  
  221.             var newNotebook = new NoteBook() {
  222.                 Name = "New notebook"
  223.             };
  224.  
  225.             DatabaseHelper.Insert(newNotebook);
  226.         }
  227.  
  228.         public void CreateNote(int id) {
  229.  
  230.             var newNote = new Note() {
  231.                 NotebookId = id,
  232.                 CratedTime = DateTime.Now,
  233.                 UpdatedTime = DateTime.Now,
  234.                 Title = "New note"
  235.             };
  236.  
  237.             DatabaseHelper.Insert(newNote);
  238.         }
  239.  
  240.         public void ReadNotebooks() {
  241.  
  242.             using (var conn = new SQLiteConnection(DatabaseHelper.dbFile)) {
  243.  
  244.                 var notebooks = conn.Table<NoteBook>().ToList();
  245.  
  246.                 NoteBooks.Clear();
  247.                 foreach (var item in notebooks) {
  248.                     NoteBooks.Add(item);
  249.                 }
  250.             }
  251.         }
  252.  
  253.         public void ReadNoote() {
  254.  
  255.             using (var conn = new SQLiteConnection(DatabaseHelper.dbFile)) {
  256.  
  257.                 if (SelectedNotebook != null) {
  258.                     var notes = conn.Table<Note>().Where(n => n.NotebookId == SelectedNotebook.Id).ToList();
  259.  
  260.                     Notes.Clear();
  261.                     foreach (var item in notes) {
  262.                         Notes.Add(item);
  263.                     }
  264.                 }
  265.             }
  266.         }
  267.  
  268.         public void Fill() {
  269.             for (int i = 0; i < Fonts.Length; i++) {
  270.                 Fonts[i] = i.ToString();
  271.             }
  272.         }
  273.  
  274.         public event PropertyChangedEventHandler PropertyChanged;
  275.  
  276.         private void OnPropertyChanged(string property) {
  277.             PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
  278.         }
  279.     }
  280. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement