The UWP Notepad Project (Redux): Find/Replace (Premium)

For this installment of our UWP project, we’ll implement Find, Find Next, Find Previous, Replace, and Replace All with a fun new custom dialog.

And I am pretty proud of that dialog. But since I already wrote about how I designed the Find and Replace dialogs as a single ContentDialog back in The UWP Files: Find Your Way Back (Premium), you can read that if you’re interested. The short version is that we display the entire dialog when the user selects the Replace button, but we hide the middle two rows of controls---the “Replace with” textblock and textbox, the Replace button, and the Replace button---when they select the Find button.

To get started, let’s add the code for this new ContentDialog, called FindReplaceDialog, to our XAML. It should go right below the SavePrompt code and look like so:
<ContentDialog x:Name="FindReplaceDialog">
    <Grid Height="Auto" Width="Auto" Margin="0,10,0,0">
        <Grid.RowDefinitions><RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <TextBlock Grid.Row="0" Grid.Column="0" Text="Find what:" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="0,0,10,0" />
        <TextBox Name="FindReplace_FindTextBox" Grid.Row="0" Grid.Column="1" Width="200" Height="32" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,0,10,0"  />
        <Button Name="FindReplace_FindButton" Grid.Row="0" Grid.Column="2" Content="Find" Width="110" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="0,0,0,10"/>
        <TextBlock Name="FindReplace_ReplaceWithTextBlock" Grid.Row="1" Grid.Column="0" Text="Replace with:" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="0,0,0,10" />
        <TextBox Name="FindReplace_ReplaceTextBox" Grid.Row="1" Grid.Column="1" Width="200" Height="32" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,0,0,10"  />
        <Button Name="FindReplace_ReplaceButton" Grid.Row="1" Grid.Column="2" Content="Replace" Width="110" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="0,0,0,10"/>
        <Button Name="FindReplace_ReplaceAllButton" Grid.Row="2" Grid.Column="2" Content="Replace All" Width="110" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="0,0,0,10"/>
        <Button Name="FindReplace_CancelButton" Grid.Row="3" Grid.Column="2" Content="Close" Width="110" HorizontalAlignment="Le...

Gain unlimited access to Premium articles.

With technology shaping our everyday lives, how could we not dig deeper?

Thurrott Premium delivers an honest and thorough perspective about the technologies we use and rely on everyday. Discover deeper content as a Premium member.

Tagged with

Share post

Please check our Community Guidelines before commenting

Windows Intelligence In Your Inbox

Sign up for our new free newsletter to get three time-saving tips each Friday

"*" indicates required fields

This field is for validation purposes and should be left unchanged.

Thurrott © 2024 Thurrott LLC