locked
How to integrate notepad into Store app RRS feed

  • Question

  • Add some notes and save that into database, in winrt have any  notepad kind of control?
    Tuesday, October 8, 2013 9:34 AM

Answers

  • The closest you can do is just add a textbox...

    Look at AcceptsReturn to allow people to press enter go to a new line...

    The properties ScrollViewer.HorizontalScrollBarVisibility and ScrollViewer.VerticalScrollBarVisibility to be able to add in visible scroll bars...although the built in ones may not be completely desirable as while their visible they can overlap text...

    If you want to disable wrapping of text, just change TextWrapping to None.

    I don't know the character limit or the practical limits for this control but if your looking for a simple notepad-like input, this will probably be good enough unless your writing just an insane amount of text in.

    • Marked as answer by Narendramacha Tuesday, October 8, 2013 1:29 PM
    Tuesday, October 8, 2013 11:11 AM

All replies

  • The closest you can do is just add a textbox...

    Look at AcceptsReturn to allow people to press enter go to a new line...

    The properties ScrollViewer.HorizontalScrollBarVisibility and ScrollViewer.VerticalScrollBarVisibility to be able to add in visible scroll bars...although the built in ones may not be completely desirable as while their visible they can overlap text...

    If you want to disable wrapping of text, just change TextWrapping to None.

    I don't know the character limit or the practical limits for this control but if your looking for a simple notepad-like input, this will probably be good enough unless your writing just an insane amount of text in.

    • Marked as answer by Narendramacha Tuesday, October 8, 2013 1:29 PM
    Tuesday, October 8, 2013 11:11 AM
  • Do you have any special requirement for the text editing. I think RichEditBox should be able to implement the common text format and editing task.

    Best Regards,

    Han Xia


    My Blog:http://blogs.msdn.com/b/hanxia


    Tuesday, October 8, 2013 11:18 AM
  • I assume Han Xia means "RichEditBox" which may also help and may or may not implement the previous things I talked about and/or work a little bit differently, if you need any specific help, such as something you want to do you don't see possible, you can ask us how to do whatever it's specifically...if you were looking for RichTextBox and just skipped over RichEditBox since it didn't have the word text in it, that's the control your actually looking for.
    Tuesday, October 8, 2013 12:01 PM
  • Thanks for your replies, I used textbox its simple and it fulfills my requirement.
    Tuesday, October 8, 2013 1:29 PM
  • Thanks for your replies, I used textbox its simple and it fulfills my requirement.
    Tuesday, October 8, 2013 1:29 PM
  • you can save text in notepad and retreive here is the code

              
      var dialog = new InputDialog();
                await dialog.ShowAsync("Title", "Text", "OK", "Cancel");
                await new MessageDialog(dialog.InputText, "WinRTXamlToolkit.Sample").ShowAsync();
                await "ABC".WriteToFile("abc.txt", KnownFolders.DocumentsLibrary);     
                await new MessageDialog("Test files written", "WinRTXamlToolkit.Sample").ShowAsync();
                var abc = await StringIOExtensions.ReadFromFile("abc.txt", KnownFolders.DocumentsLibrary);
                

    //methods
    using System;
    using System.Threading.Tasks;
    using Windows.Storage;
    using Windows.Storage.Streams;
    
    namespace WinRTXamlToolkit.IO.Extensions
    {
        /// <summary>
        /// Extensions for simple writing and reading of strings to/from files.
        /// </summary>
        /// <remarks>
        /// Note that these were created before FileIO class existed in WinRT, but they still serve a purpose.
        /// </remarks>
        public static class StringIOExtensions
        {
            /// <summary>
            /// Reads a string from a text file.
            /// </summary>
            /// <param name="fileName">Name of the file.</param>
            /// <param name="folder">The folder.</param>
            /// <returns></returns>
            public static async Task<string> ReadFromFile(
                string fileName,
                StorageFolder folder = null)
            {
                folder = folder ?? ApplicationData.Current.LocalFolder;
                var file = await folder.GetFileAsync(fileName);
    
                using (var fs = await file.OpenAsync(FileAccessMode.Read))
                {
                    using (var inStream = fs.GetInputStreamAt(0))
                    {
                        using (var reader = new DataReader(inStream))
                        {
                            await reader.LoadAsync((uint)fs.Size);
                            string data = reader.ReadString((uint)fs.Size);
                            reader.DetachStream();
    
                            return data;
                        }
                    }
                }
            }
    
            /// <summary>
            /// Writes a string to a text file.
            /// </summary>
            /// <param name="text">The text to write.</param>
            /// <param name="fileName">Name of the file.</param>
            /// <param name="folder">The folder.</param>
            /// <param name="options">
            /// The enum value that determines how responds if the fileName is the same
            /// as the name of an existing file in the current folder. Defaults to ReplaceExisting.
            /// </param>
            /// <returns></returns>
            public static async Task WriteToFile(
                this string text,
                string fileName,
                StorageFolder folder = null,
                CreationCollisionOption options = CreationCollisionOption.ReplaceExisting)
            {
                folder = folder ?? ApplicationData.Current.LocalFolder;
                var file = await folder.CreateFileAsync(
                    fileName,
                    options);
                using (var fs = await file.OpenAsync(FileAccessMode.ReadWrite))
                {
                    using (var outStream = fs.GetOutputStreamAt(0))
                    {
                        using (var dataWriter = new DataWriter(outStream))
                        {
                            if (text != null)
                                dataWriter.WriteString(text);
    
                            await dataWriter.StoreAsync();
                            dataWriter.DetachStream();
                        }
    
                        await outStream.FlushAsync();
                    }
                }
            }
        }
    }
    

    Tuesday, October 8, 2013 2:05 PM