XAML解析异常 - xmlns:x =“http://schemas.microsoft.com/winfx/2006/xaml”

时间:2012-01-28 12:54:16

标签: c# wpf xaml

我昨晚使用VS 2010 Ultimate在我的电脑上开发了一个WPF项目。

我刚刚使用VS C#2010 Express在我的上网本上打开了它。

当我尝试运行它时,我抛出一个XAML Parse异常,告诉我该行:

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

是问题所在。我看不出它的问题,我从来没有改变它,看起来它应该是它。

错误:

'The invocation of the constructor on type 'WpfApplication1.MainWindow' that matches the specified binding constraints threw an exception.' Line number '3' and line position '9'.

完整的XAML:

<Window x:Class="WpfApplication1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Camera" Height="550" Width="826" Background="#ddd" ResizeMode="NoResize" WindowStyle="None" MouseLeftButtonDown="Window_MouseLeftButtonDown" BorderBrush="#FF8D8D8D" BorderThickness="2" >
<Window.Resources>
    <Style TargetType="{x:Type Button}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Button}">
                   <ContentPresenter
              Margin="{TemplateBinding Control.Padding}"
              HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}"
              VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}"
              SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}"
              ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}"
              RecognizesAccessKey="True"
              Content="{TemplateBinding ContentControl.Content}" />
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</Window.Resources>
<Grid Width="830" Height="510">
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="132" />
        <ColumnDefinition Width="698*" />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="29" />
        <RowDefinition Height="319" />
        <RowDefinition Height="121" />
        <RowDefinition Height="16" />
        <RowDefinition Height="25*" />
    </Grid.RowDefinitions>
    <ComboBox Name="PortNames" Height="23" HorizontalAlignment="Left" VerticalAlignment="Top" Width="120" SelectionChanged="PortNames_SelectionChanged" Margin="12,6,0,0" />
    <Ellipse Grid.Row="2"  Height="120" HorizontalAlignment="Left" Name="ellipse1" StrokeThickness="6" VerticalAlignment="Top" Width="120" MouseLeftButtonDown="ellipse1_MouseLeftButtonDown" Margin="12,0,0,0">
        <Ellipse.Fill>
            <LinearGradientBrush EndPoint="1,1" StartPoint="0,0">
                <GradientStop Color="#89FF0000" Offset="0" />
                <GradientStop Color="Red" Offset="1" />
            </LinearGradientBrush>
        </Ellipse.Fill>
        <Ellipse.Stroke>
            <LinearGradientBrush EndPoint="1,1" StartPoint="0,0">
                <GradientStop Color="#FFB10000" Offset="0" />
                <GradientStop Color="#83B20707" Offset="0" />
                <GradientStop Color="#F7B00000" Offset="1" />
            </LinearGradientBrush>
        </Ellipse.Stroke>
    </Ellipse>
    <Button Content="Sync" Height="23" HorizontalAlignment="Left" Margin="57,6,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" Grid.Row="1" />
    <Rectangle Height="23" HorizontalAlignment="Left" Margin="12,6,0,0" Name="rectangle2" Stroke="Black" VerticalAlignment="Top" Fill="Red" Width="39" OpacityMask="#AA000000" Grid.Row="1" />
    <ProgressBar Grid.Row="4"  Height="19" HorizontalAlignment="Left" Name="progressBar1" VerticalAlignment="Top" Width="120" Margin="12,2,0,0" />
    <Rectangle Grid.RowSpan="5" Grid.Column="1" Height="500" Name="rectangle1" Stroke="#aaa" Width="660" Fill="#eee" Margin="12,5,26,5" />
    <Button Grid.Column="1" Height="18" HorizontalAlignment="Left" Margin="630,-20,0,0" Name="image1" VerticalAlignment="Top" Width="40" Click="image1_Click"><Image Stretch="Fill" Source="/PhotoProgram;component/Images/Close.png" /></Button>
    <Button Grid.Column="1" Height="18" HorizontalAlignment="Left" Margin="587,-20,0,0" Name="minimize" VerticalAlignment="Top" Width="40" Click="minimize_Click"><Image Stretch="Fill" Source="/PhotoProgram;component/Images/Minimize.png"  /></Button>
</Grid>

4 个答案:

答案 0 :(得分:74)

XAMLParseException是WPF中引发的常见异常。不幸的是,这不是很有用。

为了帮助找出真正的错误,您可以在Visual Studio中更早地打开异常报告。默认组合键是Ctrl + Alt + E.从那里,检查所有方框。

现在,代码中抛出的异常将在调试器中突出显示。

答案 1 :(得分:3)

从参考资料中试用这个

“Ur需要dll” - &gt; properties-&gt;复制到local-&gt; true(将其更改为false)

save&amp;清洁解决方案&amp;然后重建它。我认为它会起作用(为我工作)。

答案 2 :(得分:1)

xaml看起来不错。不应该有任何问题。 我想你试着获得一些数据。你试着用你的应用程序收到一些消息吗?如果是这样,则默认消息大小为65536字节。在app.config中增加该数字。 在运行程序时也打开输出窗口并检查是否存在绑定错误。

答案 3 :(得分:0)

我遇到此错误,更改异常报告似乎没有帮助

我注意到我试图打电话:

sac ... < $1

var processClass = new ManagementClass(@"\server.domain1.co.uk\root\cimv2:Win32_Process"); 应该是\server

更改此问题解决了这个问题,但是如果出现错误消息并且没有告诉您有关错误的信息,则会非常烦人。

在wpf中没有正确形成字符串的情况下,我在几个地方实际上注意到了这个错误,所以这可能是一个很好的起点。