开发者

Binding with an escaped string format breaks VS IDE and intellisense

开发者 https://www.devze.com 2023-02-14 12:06 出处:网络
In Silverlight, I\'ve got a hyperlinkbutton defined as the following: <HyperlinkButton Content=\"{Binding FileName}\" NavigateUri=\"{Binding MailLogAttachmentID, StringFormat=\\/DownloadFile.aspx?

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 开发者_C百科I can get this functionality without breaking the designer?


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}}" />
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号