Josh
Josh

Reputation: 10604

Binding with an escaped string format breaks VS IDE and intellisense

In Silverlight, I've got a hyperlinkbutton defined as the following:

<HyperlinkButton Content="{Binding FileName}" NavigateUri="{Binding MailLogAttachmentID, StringFormat=\/DownloadFile.aspx?objecttype\=proposalattachment&amp;id\=\{0\}}" />

When I try to view the designer, instead of the XAML, I get a Unhandled Exception has occurred error (Index (zero based) must be greater than or equal to zero and less than the size of the argument list) and it gives me the option of reloading the designer. This also breaks any intellisense while developing in XAML. If I remove the NavigateUri StringFormat expression, all is well. The application compiles fine and the hyperlink button works as expected.

Is there another way I can get this functionality without breaking the designer?

Upvotes: 2

Views: 1080

Answers (1)

madd0
madd0

Reputation: 9323

This should do the trick, if you don't want a complicated escaped expression:

<HyperlinkButton DataContext="{StaticResource s}" Content="{Binding FileName}">
    <HyperlinkButton.NavigateUri>
        <Binding Path="MailLogAttachmentID"
                 StringFormat="/DownloadFile.aspx?objecttype=proposalattachment&amp;id={0}" />
    </HyperlinkButton.NavigateUri>
</HyperlinkButton>

In any case, the character that was generating the exception was the ampersand, so if you write it like this, it should work too:

<HyperlinkButton Content="{Binding FileName}"
                 NavigateUri="{Binding MailLogAttachmentID, StringFormat=/DownloadFile.aspx?objecttype\=proposalattachment&amp;amp;id\={0}}" />

Upvotes: 6

Related Questions