Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- XAML
- ----------------------------------------------------------------------
- <Page x:Name="Main"
- x:Class="uwpEvernote.View.NotesPage"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:local="using:uwpEvernote.View"
- xmlns:vm="using:uwpEvernote.ViewModel"
- xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
- xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
- mc:Ignorable="d"
- Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
- <Page.Resources>
- <vm:NotesVM x:Key="VM" />
- <SolidColorBrush x:Key="enabled"
- Color="#0078D4" />
- <SolidColorBrush x:Key="disabled"
- Color="Transparent" />
- </Page.Resources>
- <RelativePanel x:Name="Container"
- DataContext="{StaticResource VM}">
- <RelativePanel.Background>
- <SolidColorBrush Color="{ThemeResource SystemRevealListMediumColor}" />
- </RelativePanel.Background>
- <MenuBar x:Name="menuBar">
- <MenuBarItem Title="File">
- <MenuFlyoutItem Text="New notebook"
- Command="{Binding NewNotebookCommand}">
- <MenuFlyoutItem.Icon>
- <FontIcon Glyph="" />
- </MenuFlyoutItem.Icon>
- </MenuFlyoutItem>
- <MenuFlyoutItem Text="New Note"
- Command="{Binding NewNoteCommand}"
- CommandParameter="{Binding SelectedNotebook}">
- <MenuFlyoutItem.Icon>
- <FontIcon Glyph="" />
- </MenuFlyoutItem.Icon>
- </MenuFlyoutItem>
- <MenuFlyoutSeparator />
- <MenuFlyoutItem Text="Exit"
- Command="{Binding ExitCommand}">
- <MenuFlyoutItem.Icon>
- <FontIcon Glyph="" />
- </MenuFlyoutItem.Icon>
- </MenuFlyoutItem>
- </MenuBarItem>
- </MenuBar>
- <ListView x:Name="Notebook"
- RelativePanel.Below="menuBar"
- Width="140"
- SelectedItem="{Binding SelectedNotebook, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
- ItemsSource="{Binding NoteBooks}"
- RelativePanel.AlignBottomWithPanel="True">
- <ListView.ItemTemplate>
- <DataTemplate>
- <TextBlock Text="{Binding Name}" />
- </DataTemplate>
- </ListView.ItemTemplate>
- </ListView>
- <ListView x:Name="Notes"
- Width="140"
- ItemsSource="{Binding Notes}"
- RelativePanel.Below="menuBar"
- RelativePanel.RightOf="Notebook"
- RelativePanel.AlignBottomWithPanel="True">
- <ListView.ItemTemplate>
- <DataTemplate>
- <TextBlock Text="{Binding Title}" />
- </DataTemplate>
- </ListView.ItemTemplate>
- </ListView>
- <CommandBar x:Name="commandBar"
- RelativePanel.Below="menuBar"
- RelativePanel.RightOf="Notes"
- RelativePanel.AlignRightWithPanel="True"
- OverflowButtonVisibility="Collapsed"
- VerticalAlignment="Center"
- Margin="0,10,20,10"
- Background="{ThemeResource ButtonBackgroundThemeBrush}">
- <CommandBar.Content>
- <StackPanel Orientation="Horizontal">
- <AppBarButton x:Name="textToSpeech"
- Icon="Microphone"
- Click="Actions_Click"
- Tag="0"
- ToolTipService.ToolTip="Text to speech" />
- <AppBarButton x:Name="playBtn"
- Icon="Play"
- Click="Actions_Click"
- Tag="5"
- ToolTipService.ToolTip="Read" />
- <AppBarButton x:Name="FormatBoltText"
- ToolTipService.ToolTip="Bold"
- Icon="Bold"
- Tag="1"
- Click="Actions_Click" />
- <AppBarButton x:Name="formatItalicText"
- ToolTipService.ToolTip="Italic"
- Icon="Italic"
- Tag="2"
- Click="Actions_Click" />
- <AppBarButton x:Name="formatUnderlineText"
- ToolTipService.ToolTip="Underline"
- Icon="Underline"
- Tag="3"
- Click="Actions_Click" />
- <AppBarSeparator />
- <ComboBox IsEditable="True"
- Tag="1"
- ItemsSource="{Binding Fonts}"
- Loaded="fontBox_Loaded"
- x:Name="fontBox"
- SelectionChanged="ComboChanged"
- Width="150"
- TextSubmitted="fontBox_TextSubmitted"
- />
- <ComboBox x:Name="fontSizeBox"
- ItemsSource="{Binding FontsSize}"
- Tag="2"
- TextSubmitted="fontBox_TextSubmitted"
- SelectionChanged="ComboChanged"
- IsEditable="True"
- Margin="10,0,0,0" />
- </StackPanel>
- </CommandBar.Content>
- </CommandBar>
- <Canvas x:Name="recognitionCanvas"
- Visibility="Collapsed"
- RelativePanel.RightOf="Notes"
- RelativePanel.Below="commandBar"
- RelativePanel.AlignRightWithPanel="True"
- RelativePanel.AlignBottomWith="Notebook"
- Margin="0,0,10,40" />
- <InkCanvas x:Name="drawingCanvas"
- Visibility="Collapsed"
- RelativePanel.RightOf="Notes"
- RelativePanel.Below="commandBar"
- RelativePanel.AlignRightWithPanel="True"
- RelativePanel.AlignBottomWith="Notebook"
- Margin="0,0,10,40" />
- <RichEditBox x:Name="richEbitBox"
- IsHandwritingViewEnabled="False"
- TextChanged="Cotent_TextChanged"
- RelativePanel.RightOf="Notes"
- RelativePanel.Below="commandBar"
- RelativePanel.AlignRightWithPanel="True"
- RelativePanel.AlignBottomWith="Notebook"
- Margin="0,0,10,40" />
- <CommandBar RelativePanel.RightOf="Notes"
- RelativePanel.AlignBottomWith="richEbitBox"
- RelativePanel.AlignRightWithPanel="True"
- Margin="0,0,10,0"
- HorizontalAlignment="Left"
- VerticalAlignment="Center">
- <CommandBar.Content>
- <TextBlock x:Name="charactersCount"/>
- </CommandBar.Content>
- </CommandBar>
- </RelativePanel>
- </Page>
- NotesViewModel
- ------------------------------------------------------
- using Microsoft.Graphics.Canvas.Text;
- using SQLite;
- using System;
- using System.Collections.ObjectModel;
- using System.ComponentModel;
- using uwpEvernote.Model;
- using Windows.UI.Xaml.Controls;
- namespace uwpEvernote.ViewModel {
- public class NotesVM: INotifyPropertyChanged {
- public ObservableCollection<NoteBook> NoteBooks { get; set; }
- private NoteBook _SelectedNotebook;
- public NoteBook SelectedNotebook {
- get { return _SelectedNotebook; }
- set {
- if (value != _SelectedNotebook) {
- _SelectedNotebook = value;
- //OnPropertyChanged("SelectedNotebook");
- }
- }
- }
- public int[] FontsSize { get; set; }
- public string[] Fonts { get; set; }
- public ObservableCollection<Note> Notes { get; set; }
- public NewNoteCommand NewNoteCommand { get; set; }
- public NewNotebookCommand NewNotebookCommand { get; set; }
- public ExitCommand ExitCommand { get; set; }
- public NotesVM() {
- NewNoteCommand = new NewNoteCommand(this);
- NewNotebookCommand = new NewNotebookCommand(this);
- ExitCommand = new ExitCommand(this);
- NoteBooks = new ObservableCollection<NoteBook>();
- Notes = new ObservableCollection<Note>();
- Fonts = new string [CanvasTextFormat.GetSystemFontFamilies().Length];
- 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};
- Fill();
- ReadNotebooks();
- }
- public void CreateNotebook() {
- var newNotebook = new NoteBook() {
- Name = "New notebook"
- };
- DatabaseHelper.Insert(newNotebook);
- }
- public void CreateNote(int id) {
- var newNote = new Note() {
- NotebookId = id,
- CratedTime = DateTime.Now,
- UpdatedTime = DateTime.Now,
- Title = "New note"
- };
- DatabaseHelper.Insert(newNote);
- }
- public void ReadNotebooks() {
- using (var conn = new SQLiteConnection(DatabaseHelper.dbFile)) {
- var notebooks = conn.Table<NoteBook>().ToList();
- NoteBooks.Clear();
- foreach (var item in notebooks) {
- NoteBooks.Add(item);
- }
- }
- }
- public void ReadNoote() {
- using (var conn = new SQLiteConnection(DatabaseHelper.dbFile)) {
- if (SelectedNotebook != null) {
- var notes = conn.Table<Note>().Where(n => n.NotebookId == SelectedNotebook.Id).ToList();
- Notes.Clear();
- foreach (var item in notes) {
- Notes.Add(item);
- }
- }
- }
- }
- public void Fill() {
- for (int i = 0; i < Fonts.Length; i++) {
- Fonts[i] = i.ToString();
- }
- }
- public event PropertyChangedEventHandler PropertyChanged;
- private void OnPropertyChanged(string property) {
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement