为什么运行简单的文本块应用程序,带有按钮的简单应用程序在WPF中失败

Lea*_*ner 0 c# silverlight wpf wpf-controls silverlight-4.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>
Run Code Online (Sandbox Code Playgroud)

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

<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>
Run Code Online (Sandbox Code Playgroud)

Mar*_*eta 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>
Run Code Online (Sandbox Code Playgroud)