XAML Visual Studio中用于自动滚动的列表框控件

raogr8fs  于 2022-12-07  发布在  其他
关注(0)|答案(1)|浏览(155)

我正在使用一个WPF主窗口,并且使用了一个列表框,我希望列表框在添加新数据时自动滚动。我在this question的选择答案中使用了ListBoxBehavior类,并且在代码中为该类添加了以下命名空间:

using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Windows;
using System.Windows.Controls;
using System.ComponentModel;

另外,在我的XAML中,我添加了以下内容:

<ListBox x:Name="IncomingData" FontSize="20" Grid.Column="1" Margin="10,10,10,0" Grid.Row="3" ItemsSource="{Binding SourceCollection}" lb:ListBoxBehavior.ScrollOnNewItem="true"/>

但是,在我的XAML代码中,关于该行,出现了以下三个错误,它们如下所示:

  1. Error XDG0006 The namespace prefix "lb" is not defined .
  2. Error XDG0008 ListBoxBehavior is not supported in a Windows Presentation Foundation (WPF) project .
  3. Error XLS0415 The attachable property 'ScrollOnNewItem' was not found in type 'ListBoxBehavior' .
    我试着在ListBoxBehavior类中创建ListBox类型的对象ListBox lb = new ListBox();,但这并没有改变这种情况。另外,ScrollOnNewItem已经存在于类中,为什么它没有标识它呢?是否有我应该做的遗漏步骤?任何帮助都非常感谢!
k3bvogb1

k3bvogb11#

您需要在使用lb名称空间之前定义它。
在你的xaml文件的顶部你应该看到xmlns:x ="..."。注意你是和x:Name一起使用的。
lb也是一样。你需要定义xmlns:lb ="..."。intellisense应该帮助你填写"..."。
注意,xmlns表示XML命名空间。
这应该能消除所有三个错误。

相关问题