how to make a "take it back" button i mean if i write something to textbox like "e" and if i click take it back it will delete it i also want to make the reverse of take it back button check the photo btw this is in WPF .net 3

deniz koyuncu 21 Reputation points
2022-03-26T08:25:24.88+00:00

187095-image.png

Developer technologies | Visual Studio | Other
Developer technologies | Visual Studio | Other
A family of Microsoft suites of integrated development tools for building applications for Windows, the web, mobile devices and many other platforms. Miscellaneous topics that do not fit into specific categories.
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Castorix31 91,496 Reputation points
    2022-03-26T10:02:28.537+00:00

    A basic way :

    187151-undo-redo.gif

        <StackPanel Orientation="Horizontal" Margin="10">  
            <Button x:Name='buttonUndo'  
             Command="ApplicationCommands.Undo" CommandTarget="{Binding ElementName=textBox1}"   
             HorizontalAlignment="Left" Height="40" Width="40" FontFamily='Segoe UI Emoji' FontSize='20' Content='&#x21B6;' Click="buttonUndo_Click"/>  
            <Button x:Name='buttonRedo'   
             Command="ApplicationCommands.Redo" CommandTarget="{Binding ElementName=textBox1}"  
             HorizontalAlignment="Left" Height="40" Width="40" FontFamily='Segoe UI Emoji' FontSize='20' Content='&#x21B7;' Click="buttonRedo_Click"/>  
        </StackPanel>  
        <TextBox x:Name="textBox1" HorizontalAlignment="Left" Height="27" Margin="10,10,0,0" VerticalAlignment="Top" Width="225" />  
    

    Code behind :

        private void buttonUndo_Click(object sender, RoutedEventArgs e)  
        {  
            textBox1.Undo();  
        }  
    
        private void buttonRedo_Click(object sender, RoutedEventArgs e)  
        {  
            textBox1.Redo();  
        }  
    
    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.