Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WPF项目上的XAML.Parse.Exception';s部署_Wpf - Fatal编程技术网

WPF项目上的XAML.Parse.Exception';s部署

WPF项目上的XAML.Parse.Exception';s部署,wpf,Wpf,我在部署WPF项目时遇到了一个问题,部署的项目在启动时崩溃,并生成一个XAML.Parse.Exception,第4行位置70处的内部异常为“不能在同一实例上嵌套BeginInit调用”。该应用程序对我的计算机具有完全权限。我问这个问题是因为关于这个问题的几个问题没有真正解决问题的办法 下面是它在前几行引用的XAML代码 <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xml

我在部署WPF项目时遇到了一个问题,部署的项目在启动时崩溃,并生成一个XAML.Parse.Exception,第4行位置70处的内部异常为“不能在同一实例上嵌套BeginInit调用”。该应用程序对我的计算机具有完全权限。我问这个问题是因为关于这个问题的几个问题没有真正解决问题的办法

下面是它在前几行引用的XAML代码

<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="ASRV.MainWindow"
    Title="ASRV GUI" Height="768" Width="1024" ResizeMode="CanMinimize">
<Window.Resources>
</Window.Resources>
<Window.Background>
    <ImageBrush ImageSource="pack://siteoforigin:,,,/background.png"/>
</Window.Background>

我猜原因是:

<Window.Background>
    <ImageBrush ImageSource="pack://siteoforigin:,,,/background.png"/>
</Window.Background>

您可能在同一窗口或子控件中的其他位置重用此图像


BeginInit在数据绑定中被调用,这是我在示例代码中看到的唯一数据绑定的东西。“BeginInit在同一个实例上调用”指出它被绑定了两次

正如@basarat在回答中所说,每当一个对象尝试绑定两次时,就会遇到这个错误。在OP中看到的示例之后,我遇到了在我的案例中通过在CodeBehind和xaml中设置DataContext而导致的相同错误:

在MainWindow.xaml文件中,我有以下内容:

<Window xmlns:vm="clr-namespace:MyApp.ViewModel"
    [...more xmlns references skipped for brevity...]
    <!--the next three lines caused a problem, when combined with the code behind-->
    <Window.DataContext>
        <vm:MainViewModel/>
    </Window.DataContext>
</Window>


为什么有一个空的
窗口。Resources
元素?实际的异常是什么?我认为它不是
XAML.Parse.Exception
。可能是
XamlParseException
?Windows.Resources为空,因为我不熟悉样式设置,所以正在查看其中是否有内容。是的,这是我想说的例外。这确实是个问题。谢谢@basarat当一个ResourceDictionary中的资源基于另一个ResourceDictionary中的资源时,是否也会发生这种情况?
namespace MyApp.View
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainViewModel MainViewModel { get; set; }
        public MainWindow()
        {
            bool success = false;
            MainViewModel = new MainViewModel();
            // This line caused the problem in combination with the xaml above
            DataContext = MainViewModel;
            InitializeComponent();
        }
    }
}