Advertisement
eduardogr

Untitled

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