0

伙计们,当我将下面的代码粘贴到记事本中并保存为 test.xaml 并运行它时,我看到下面的代码给出了运行时错误。

<Page xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <TextBlock Text="Hi Ramakrishnan, good morning"/>
    <Button x:Name=”blueButton”
        Width=”100”
        Height=”40”
        Background=”Blue”
        Content=”Click Me” />
</Page>

但是下面的代码没有给出任何错误,而是在浏览器中非常正确地显示了文本块内容。有什么想法吗 ?我还检查了包括一个文本框来代替上面的按钮,仍然是同样的错误。

<Page xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <TextBlock Text="Hi Ramakrishnan, good morning"/>
</Page>
4

2 回答 2

5

您需要将 TextBlock/Button 包装在 StackPanel 或其他允许其内容中包含多个控件的控件中。

<StackPanel Orientation="Horizontal">
        <TextBlock Text="Hi Ramakrishnan, good morning"/>
        <Button x:Name="blueButton"
        Width="100"
        Height="40"
        Background="Blue"
        Content="Click Me" />
    </StackPanel>
于 2012-08-07T12:47:38.523 回答
1

Your pasted code is using "smart quotes" instead of "normal quotes" on the button.

<TextBlock Text="Hi Ramakrishnan, good morning"/>  <-- normal quotes
<Button x:Name=”blueButton”                        <-- smart quotes

Have you edited or saved or pasted this through MSWord, perhaps?

(If this isn't the problem then it's possible that what you've pasted in your question isn't exactly what you have in your Xaml file, in which case you should update your question...)

于 2012-08-07T12:46:45.873 回答