【问题标题】:Use control from cs file (wpf)使用来自 cs 文件的控制 (wpf)
【发布时间】:2013-01-31 10:28:05
【问题描述】:

对不起,我是 C# 和 WPF 的新手。 我尝试使用从 *.cs 文件下载的第 3 方控制: http://www.codeproject.com/Articles/75847/Virtualizing-WrapPanel

文章描述使用控件:

<ListBox ItemsSource="{StaticResource boundCollection}">
   <ListBox.ItemsPanel>
       <ItemsPanelTemplate>
            <VirtualizingWrapPanel Orientation="Vertical" /> 
       </ItemsPanelTemplate>
    </ListBox.ItemsPanel> 
</ListBox>

我已将 cs 文件复制到我的项目文件夹中,并通过拖放将其添加到解决方案资源管理器中,然后将命名空间更改为我项目的命名空间。但它显示以下错误:

Error   1   The tag 'VirtualizingWrapPanel' does not exist in XML namespace 'http://schemas.microsoft.com/winfx/2006/xaml/presentation'. Line 30 Position 22.   C:\Users\mbp2011\Documents\Visual Studio 2010\Projects\@Experiment\ThumbnailsView\ThumbnailsView\MainWindow.xaml    30  22  ThumbnailsView

提前致谢

【问题讨论】:

标签: c# wpf user-controls


【解决方案1】:

你必须在你的 Xaml 中添加一个引用,它与在你的 cs 文件中添加一个引用(使用)相同

例子:

<Window x:Class="WpfApplication8.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        // Add a reference to the namespace that contains VirtualizingWrapPanel 
        xmlns:controls="clr-namespace:the namespace of the VirtualizingWrapPanel"

        Title="MainWindow" Height="233" Width="405" Name="UI" WindowStyle="ToolWindow">
    <ListBox ItemsSource="{StaticResource boundCollection}">
        <ListBox.ItemsPanel>
            <ItemsPanelTemplate>

                // then use the namespace to access the VirtualizingWrapPanel 
                <controls:VirtualizingWrapPanel Orientation="Vertical" />
            </ItemsPanelTemplate>
        </ListBox.ItemsPanel>
    </ListBox>
</Window>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-06-04
    • 2016-10-05
    • 1970-01-01
    • 2015-12-19
    • 2011-05-18
    • 2010-10-03
    • 1970-01-01
    • 2011-02-05
    相关资源
    最近更新 更多