WPF XAML 编译错误 - 名称空间中不存在名称 [英] WPF XAML compile error- the name does not exist in the namespace

查看:31
本文介绍了WPF XAML 编译错误 - 名称空间中不存在名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试添加从 WPF 应用程序中查看 PDF 文件的功能.

我一直在关注教程:

I am trying to add the capability to view a PDF file from within my WPF application.

I have been following the tutorial at: http://www.codeproject.com/Articles/579878/MoonPdfPanel-A-WPF-based-PDF-Viewer-Control#include, and am at the section titled "Including MoonPdfPanel in your Application".

I have the following XAML:

<Window x:Class="DocumentViewer.MainWindow"
    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"
    xmlns:local="clr-namespace:DocumentViewer"
    xmlns:mpp="DocumentViewer:MoonPdfLib;assembly=MoonPdfLib"
    mc:Ignorable="d"
    Title="MainWindow" Height="350" Width="525">
  <DockPanel>
    <mpp:MoonPdfPanel Background="LightGray" ViewType="SinglePage" PageDisplay="ContinuousPages" PageMargin="0,2,4,2" AllowDrop="True"/>

    <Grid DockPanel.Dock="Top">
        <Menu x:Name="menu" IsMainMenu="True" HorizontalAlignment="Left" Height="20" VerticalAlignment="Top" Width="518">
            <MenuItem Header="_File">
                <MenuItem x:Name="loadDocument" Header="Load Document" Click="openFileMenuItem_click"></MenuItem>
                <Separator />
                <MenuItem x:Name="exit" Header="Exit" Click="exitApplication_click"></MenuItem>
            </MenuItem>
        </Menu>
    </Grid>
    <Grid x:Name="browserHost" DockPanel.Dock="Top"   Margin="0,0,0,0">
    </Grid>
    <!--mpp:MoonPdfPanel x:Name="PdfPanel" Background="LightGray" ViewType="SinglePage" PageMargin="0,2,4,2" AllowDrop="True" /-->
    <!--mpp:MoonPdfPanel Background="LightGray" ViewType="SinglePage" PageDisplay="ContinuousPages" PageMargin="0,2,4,2" AllowDrop="True"/-->


  </DockPanel>

</Window>

However, for some reason, I am getting a compile error on the line:

        <mpp:MoonPdfPanel Background="LightGray" ViewType="SinglePage" PageDisplay="ContinuousPages" PageMargin="0,2,4,2" AllowDrop="True"/>

which says:

The name "MoonPdfPanel" does not exist in the namespace "DocumentViewer:MoonPdfLib

I downloaded the MoonPdfViewer from https://sourceforge.net/projects/moonpdf/?source=typ_redirect, and have ensured that it is in the root of my workspace... as far as I can tell, I have followed everything the tutorial says to do, and yet I am getting this compile error...

If I try to run the application, when it tells me that there were build errors, and asks if I would like to continue and run the last successful build, if I say 'No', 3 errors are shown in the console:

The name "MoonPdfPanel" does not exist in the namespace "DocumentViewer:MoonPdfLib;assembly=MoonPdfLib".

The property 'PageDisplay' was not found in the type 'MoonPdfPanel'.

The property 'PageDisplay' does not exist in XML namespace 'clr-namespace:MoonPdfLib;assembly=MoonPdfLib'. Line 11 Position 72.

What am I doing wrong here? How can I add this MoonPdfPanel to my application?

解决方案

Just by looking at your code and the link you provided, your namespace is wrong.

You have:

xmlns:mpp="DocumentViewer:MoonPdfLib;assembly=MoonPdfLib"

It should be:

xmlns:mpp="clr-namespace:MoonPdfLib;assembly=MoonPdfLib"

Your local namespace may be DocumentViewer, but namespaces for 3rd party libraries use the project references. So, you don't include your namespace unless it's an actual component in your namespace, such as your own custom control. Even then, the namespace is delimited with a period, ., not a colon.

The panel is added as such:

<mpp:MoonPdfPanel Name="pdfPanel" DockPanel.Dock="Bottom" Background="LightGray" 
    ViewType="SinglePage" PageRowDisplay="ContinuousPageRows" PageMargin="0,2,4,2" AllowDrop="True"/>

I was able to load a PDF without any problems using:

     OpenFileDialog ofd = new OpenFileDialog();
     ofd.Title = "Select a PDF File";
     ofd.Filter = "PDF File (*.pdf)|*.pdf";
     if ((bool)ofd.ShowDialog())
     {
        pdfPanel.OpenFile(ofd.FileName);
     }

The result looked like this:

这篇关于WPF XAML 编译错误 - 名称空间中不存在名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆