Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Code-Behind
- using Microsoft.Graphics.Canvas.Text;
- using System;
- using System.Collections;
- using System.Diagnostics;
- using Windows.Media.SpeechRecognition;
- using Windows.UI.Popups;
- using Windows.UI.Text;
- using Windows.UI.Xaml;
- using Windows.UI.Xaml.Controls;
- using Windows.UI.Xaml.Media;
- // The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238
- namespace uwpEvernote.View {
- /// <summary>
- /// An empty page that can be used on its own or navigated to within a Frame.
- /// </summary>
- public sealed partial class NotesPage: Page {
- public NotesPage() {
- this.InitializeComponent();
- var fonts = CanvasTextFormat.GetSystemFontFamilies();
- fontBox.ItemsSource = fonts;
- var arrList = new ArrayList();
- for (int i = 0; i < 73; ++i) {
- arrList.Add(i);
- }
- fontSizeBox.ItemsSource = arrList;
- }
- private void Cotent_TextChanged(object sender, RoutedEventArgs e) {
- richEbitBox.Document.GetText(TextGetOptions.None, out string value);
- charactersCount.Text = (value.Length - 1).ToString();
- }
- private async void Actions_Click(object sender, RoutedEventArgs e) {
- var id = sender as Button;
- switch (id.Tag) {
- case "0":
- using (SpeechRecognizer recognizer = new SpeechRecognizer()) {
- await recognizer.CompileConstraintsAsync();
- var result = await recognizer.RecognizeWithUIAsync();
- var dialog = new MessageDialog(result.Text, "Text spoken");
- await dialog.ShowAsync();
- richEbitBox.Document.GetText(TextGetOptions.None, out string value);
- richEbitBox.Document.SetText(TextSetOptions.None, value += result.Text);
- }
- break;
- case "1":
- if (richEbitBox.Document.Selection.CharacterFormat.Bold == FormatEffect.On) {
- richEbitBox.Document.Selection.CharacterFormat.Bold = FormatEffect.Off;
- FormatBoltText.Background = (SolidColorBrush)Resources["disabled"];
- } else {
- richEbitBox.Document.Selection.CharacterFormat.Bold = FormatEffect.On;
- FormatBoltText.Background = (SolidColorBrush)Resources["enabled"];
- }
- break;
- case "2":
- if (richEbitBox.Document.Selection.CharacterFormat.Italic == FormatEffect.On) {
- richEbitBox.Document.Selection.CharacterFormat.Italic = FormatEffect.Off;
- formatItalicText.Background = (SolidColorBrush)Resources["disabled"];
- } else {
- richEbitBox.Document.Selection.CharacterFormat.Italic = FormatEffect.On;
- formatItalicText.Background = (SolidColorBrush)Resources["enabled"];
- }
- break;
- case "3":
- if (richEbitBox.Document.Selection.CharacterFormat.Underline == UnderlineType.Single) {
- richEbitBox.Document.Selection.CharacterFormat.Underline = UnderlineType.None;
- formatUnderlineText.Background = (SolidColorBrush)Resources["disabled"];
- } else {
- richEbitBox.Document.Selection.CharacterFormat.Underline = UnderlineType.Single;
- formatUnderlineText.Background = (SolidColorBrush)Resources["enabled"];
- }
- break;
- default:
- break;
- }
- }
- private void ComboChanged(object sender, SelectionChangedEventArgs e) {
- var id = sender as ComboBox;
- switch (id.Tag) {
- case "1":
- //Todo implement new font
- string fontName = id.SelectedItem.ToString();
- richEbitBox.Focus(FocusState.Pointer);
- richEbitBox.Document.Selection.SetRange(0, richEbitBox.Document.Selection.EndPosition);
- richEbitBox.Document.Selection.CharacterFormat.Name = fontName;
- break;
- case "2":
- var size = (float)id.SelectedItem;
- richEbitBox.Focus(FocusState.Pointer);
- richEbitBox.Document.Selection.SetRange(0, richEbitBox.Document.Selection.EndPosition);
- richEbitBox.Document.Selection.CharacterFormat.Size = size;
- break;
- default:
- break;
- }
- }
- private void Container_Loaded(object sender, RoutedEventArgs e) {
- fontBox.Text = richEbitBox.Document.GetDefaultCharacterFormat().Name;
- fontSizeBox.Text = richEbitBox.Document.GetDefaultCharacterFormat().Size.ToString();
- }
- }
- }
- 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}"
- Background="{ThemeResource SystemChromeLowColor}"
- Loaded="Container_Loaded">
- <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 SystemChromeLowColor}">
- <CommandBar.Content>
- <StackPanel Orientation="Horizontal">
- <AppBarButton x:Name="textToSpeech"
- Icon="Microphone"
- Click="Actions_Click"
- Tag="0"
- ToolTipService.ToolTip="Text to speech" />
- <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" />
- <ComboBox IsEditable="True"
- Tag="1"
- x:Name="fontBox"
- SelectionChanged="ComboChanged"
- Width="150" />
- <ComboBox x:Name="fontSizeBox"
- Tag="2"
- SelectionChanged="ComboChanged"
- IsEditable="True"
- Margin="10,0,0,0"
- />
- </StackPanel>
- </CommandBar.Content>
- </CommandBar>
- <RichEditBox x:Name="richEbitBox"
- TextChanged="Cotent_TextChanged"
- RelativePanel.RightOf="Notes"
- RelativePanel.Below="commandBar"
- RelativePanel.AlignRightWithPanel="True"
- RelativePanel.AlignBottomWith="Notebook"
- Margin="0,0,10,40" />
- <CommandBar Background="{ThemeResource SystemChromeLowColor}"
- RelativePanel.RightOf="Notes"
- RelativePanel.AlignBottomWith="richEbitBox"
- RelativePanel.AlignRightWithPanel="True"
- Margin="0,0,10,0"
- HorizontalAlignment="Left"
- VerticalAlignment="Center">
- <CommandBar.Content>
- <StackPanel Orientation="Horizontal"
- HorizontalAlignment="Center"
- VerticalAlignment="Center"
- Margin="0,10,0,0">
- <TextBlock Text="Count"
- VerticalAlignment="Center"
- HorizontalAlignment="Center" />
- <TextBlock Text="|"
- Margin="10,0,0,0" />
- <TextBlock x:Name="charactersCount"
- Margin="10,0,0,0" />
- </StackPanel>
- </CommandBar.Content>
- </CommandBar>
- </RelativePanel>
- </Page>
- NotesVM
- using SQLite;
- using System;
- using System.Collections.ObjectModel;
- using System.ComponentModel;
- using System.Data.SqlClient;
- using uwpEvernote.Model;
- using uwpEvernote.ViewModel.Commands;
- 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 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>();
- 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 event PropertyChangedEventHandler PropertyChanged;
- private void OnPropertyChanged(string property) {
- PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(property));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement