Search code examples
xamlonenote

OneNote 2010 code cannot be properly pasted back into XAML


Does anyone else experience this? If I want to paste code from OneNote2010 it does simply not work.

Reproduction: Create any WPF app, copy the XAML into OneNote2010, copy it back -> Whitespace issues.

Or use this sample:

<Popup Placement="Center" IsOpen="{Binding Error, Converter={StaticResource StringBoolConverter}}" PopupAnimation="Slide">
        <userControls:ErrorMessageControl></userControls:ErrorMessageControl>
    </Popup>

After putting it into OneNote and copying it back it gets broken. I can't even paste it here as it never gets displayed.

Pasting it in XAML creates messages like

Error 1 " " is not valid in a name. MainWindow.xaml 94

Error 2 White space is missing. MainWindow.xaml 94

Seems like many whitespaces are odd for the editor.

I've compared the pasted code in Notepad++ and displayed non printable characters and I do not to see any issues with the whitespaces.


Solution

  • Set paste option to "Text Only" when pasting into OneNote.

    When pasting, open the menu and select "Text Only"; then open the menu again and set it as default paste.

    Paste Options with "Set as default" highlighted

    If the menu is not shown when pasting, go to File -> Options -> Advanced, then in "Editing" group make sure that "Show Paste Options button when content is pasted" is checked.