MrBool
You must be logged in to give feedback. Click here to login
[Close]

You must be logged to download.

Click here to login

[Close]

MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation

[Close]

MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation

How to make a note-taking application for Windows 8 using C#

In this article, we will continue with the interface that is created for Windows 8 application. This interface is used to create a not-taking application which is made using C#.

[close]

You didn't like the quality of this content?

Would you like to comment what you didn't like?

Note: To have a better understanding, go through the article on creating the interface for windows 8 application as it is a continuation of that article.

In this article, some real coding will be done by following various steps. In this, the user needs to double click on the button which is created in the interface. This double clicking is done to create the Click function for that button. As the button is clicked, the user needs to go back to the menu, but if the user is already in the menu then there is no need for this.

Listing 1: Shows the code to create the function for the button

private void SaveClose_Click(object sender, RoutedEventArgs e)
{
    // If we are in text editing mode.
    if (Notepad.Visibility == Visibility.Visible)
    {
        // Go back to main menu.
        Notepad.Visibility = Visibility.Collapsed;
        NotesGrid.Visibility = Visibility.Visible;
    }
}

Going back to the main menu, will only close the Notepad but the note is not saved. When the new note is created, then the user wants this to be included in the NotesGrid. For this, we will be creating a new Textblock inside the memory and finally it is added to the NotedGrid so that it is appeared in it. This can also be done via the interface editor as explained in the article on creating the interface.

Listing 2: Shows the code to create the new Textblock

Private void SaveClose_Click(object sender, RoutedEventArgs e)
{
    // If we are in text editing mode.
    if (Notepad.Visibility == Visibility.Visible)
    {
        // Creates a new textblock that for this note.
        TextBlock block = new TextBlock();
        block.Width = 250;
        block.Height = 125;
        block.Text = Notepad.Text;
 
        // Add that note to the grid.
        NotesGrid.Items.Add(block);
 
        // Go back to main menu.
        Notepad.Visibility = Visibility.Collapsed;
        NotesGrid.Visibility = Visibility.Visible;
    }
}

Now, when the new notes are created, a textblock which is created in the previous step will be shown under the button. If a lot of buttons are created, then they will be organized by themselves in a new column. Here, the important to be remembered is that the text is automatically cut off.

If the user wants to enable text wrapping, then the procedure is very simple. The only thing that is required to be done is to simply write block “TextWrapping = true;”

Shows the interface for the new note

Figure 1: Shows the interface for the new note

After the notes are saved, the target is not completed yet. The user might need to edit the notes created again and again. So, in this case there will be need of separate Click function for every Textblock. The function will be same for every block and by writing it once, it can be assigned to each and every Textblock.

Listing 3: Shows the code for function to be assigned to every Textblock

private void SaveClose_Click(object sender, RoutedEventArgs e)
{
    // If we are in text editing mode.
    if (Notepad.Visibility == Visibility.Visible)
    {
        // Creates a new textblock that for this note.
        TextBlock block = new TextBlock();
        block.Width = 250;
        block.Height = 125;
        block.Text = Notepad.Text;
 
        // Assign the click function.
        block.Tapped += block_Tapped;
 
        // Add that note to the grid.
        NotesGrid.Items.Add(block);
 
        // Go back to main menu.
        Notepad.Visibility = Visibility.Collapsed;
        NotesGrid.Visibility = Visibility.Visible;
    }
}
 
private void block_Tapped(object sender, TappedRoutedEventArgs e)
{
    // Get a reference to the block that has been tapped.
    TextBlock block = sender as TextBlock;
 
    // Open the text editor with the content of that block.
    Notepad.Text = block.Text;
    NotesGrid.Visibility = Visibility.Collapsed;
    Notepad.Visibility = Visibility.Visible;
 
    // Since we are currently editing this block, remove it from the menu.
    // It will be added again once we save the note.
    NotesGrid.Items.Remove(block);
}

Instead of deleting the notes, there can be a need to delete the notes. In order to do this, a new button will be added in the App Bar for it. But the App Bar can contain only one control at a time. For this, we have to add two or more button. But the problem is how it is done?

In order to it, we will place all the buttons inside a container and to do this, StickPanel will be used which is the most convenient option in this situation because it will be very easy to write it directly in the XAML editor.

Listing 4: Shows the code for buttons to be put in the container

<Page.BottomAppBar>
    <AppBar>
        <StackPanel Orientation="Horizontal">
            <Button Name="SaveClose" Style="{StaticResource AppBarButtonStyle}" Content="✔" AutomationProperties.Name="Save and Close" Click="SaveClose_Click" />
            <Button Name="Delete" Style="{StaticResource AppBarButtonStyle}" Content="" AutomationProperties.Name="Delete Selected" />
        </StackPanel>
    </AppBar>
</Page.BottomAppBar>
Shows the snapshot after writing the above code

Figure 2: Shows the snapshot after writing the above code

Now, the Delete Selected needs to click twice to write the code in it. In this case, the user needs to go through every non-button selected element in order to remove it from the GridView.

Listing 5: Shows the code to be written for deleting the selected elements

private void Delete_Click(object sender, RoutedEventArgs e)
{
    foreach (UIElement element in NotesGrid.SelectedItems)
    {
        // Don't delete the "New Note" button.
        if (element.GetType() != typeof(Button))
            NotesGrid.Items.Remove(element);
    }
}  

Once the notes are created, they are needed to be shared using the Share Contract option. This option allows the user to share content from one application to the other which can support it.

To do it, a library is needed and at the top of the MainPage.xaml.cs file, a code is added.

Listing 5: Shows the code to be added at the top of MainPage.xaml.cs file

using Windows.ApplicationModel.DataTransfer;

After this, the Windows 8 needs to be informed that the application created here is supported by it. For this, a new function needs to create which will attach the application to the Windows 8.

Listing 6: Shows the code for the new function which will inform the Windows 8

public MainPage()
{
    this.InitializeComponent();
 
    // Tell Windows 8 that our app can share.
    DataTransferManager.GetForCurrentView().DataRequested += MainPage_DataRequested;
}

Listing 7: Shows the code which will do the actual sharing

void MainPage_DataRequested(DataTransferManager sender, DataRequestedEventArgs args)
{
    // We only have text to share when a note is selected.
    if (Notepad.Visibility == Visibility.Visible)
    {
        DataPackage requestData = args.Request.Data;
        requestData.Properties.Title = "My little note";
        requestData.SetText(Notepad.Text);
    }
}

In this way, the text can be shared to other applications in an easy way.

Conclusion

We have learnt the process of using the interface to create various notes and to put them together. Instead of this, the concepts of deleting the notes and sharing them are also discussed in detail.



I am well versed with Computer Programming languages and possess good working knowledge on software languages such as C, Java, PHP, HTML and CSS

What did you think of this post?

Did you like the post?

Help us to keep publishing good contents like this.

SUPPORT US

funded

remaining

[Close]
To have full access to this post (or download the associated files) you must have MrBool Credits.

  See the prices for this post in Mr.Bool Credits System below:

Individually � in this case the price for this post is US$ 0,00 (Buy it now)
in this case you will buy only this video by paying the full price with no discount.

Package of 10 credits - in this case the price for this post is US$ 0,00
This subscription is ideal if you want to download few videos. In this plan you will receive a discount of 50% in each video. Subscribe for this package!

Package of 50 credits � in this case the price for this post is US$ 0,00
This subscription is ideal if you want to download several videos. In this plan you will receive a discount of 83% in each video. Subscribe for this package!


> More info about MrBool Credits
[Close]
You must be logged to download.

Click here to login