- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我对扩展 ListBox
的类有疑问在 Windows Phone 7 Silverlight 中。这个想法是有一个完整的ScrollViewer
(黑色,例如填满整个手机屏幕)并且 ItemsPresenter
(红色)有边距(绿色)。这用于在整个列表周围留有边距,但滚动条从右上边缘开始,到深色矩形的右下边缘结束:
问题是,ScrollViewer
无法滚动到最后,它会从列表中的最后一个元素中删除 50 个像素。如果我使用 StackPanel
而不是 VirtualizingStackPanel
边距是正确的,但列表不再是虚拟化的。
感谢您的任何想法,我已经尝试了很多,但没有任何工作。这是控制错误吗?
解决方案:使用 InnerMargin
ExtendedListBox
的属性(property)来自 MyToolkit 的控制图书馆!
C#:
public class MyListBox : ListBox
{
public MyListBox()
{
DefaultStyleKey = typeof(MyListBox);
}
}
<Application
x:Class="MyApp.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone">
<Application.Resources>
<ResourceDictionary>
<Style TargetType="local:MyListBox">
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Vertical" />
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<ScrollViewer>
<ItemsPresenter Margin="30,50,30,50" x:Name="itemsPresenter" />
</ScrollViewer>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="ItemContainerStyle">
<Setter.Value>
<Style TargetType="ListBoxItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<ContentPresenter HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
</Application.Resources>
...
</Application>
VirtualizingStackPanel
至
StackPanel
在 App.xaml 中,它按预期工作,但没有虚拟化
StackPanel
而不是
VirtualizingStackPanel
):
ObservableCollection
中添加一些逻辑或者 View 模型是没有选择的。
最佳答案
我当前的解决方案:始终更改列表最后一个元素的边距...
public Thickness InnerMargin
{
get { return (Thickness)GetValue(InnerMarginProperty); }
set { SetValue(InnerMarginProperty, value); }
}
public static readonly DependencyProperty InnerMarginProperty =
DependencyProperty.Register("InnerMargin", typeof(Thickness),
typeof(ExtendedListBox), new PropertyMetadata(new Thickness(), InnerMarginChanged));
private static void InnerMarginChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var box = (ExtendedListBox)d;
if (box.lastElement != null)
box.UpdateLastItemMargin();
box.UpdateInnerMargin();
}
private void UpdateInnerMargin()
{
if (scrollViewer != null)
{
var itemsPresenter = (ItemsPresenter)scrollViewer.Content;
if (itemsPresenter != null)
itemsPresenter.Margin = InnerMargin;
}
}
private void UpdateLastItemMargin()
{
lastElement.Margin = new Thickness(lastElementMargin.Left, lastElementMargin.Top, lastElementMargin.Right,
lastElementMargin.Bottom + InnerMargin.Top + InnerMargin.Bottom);
}
private FrameworkElement lastElement = null;
private Thickness lastElementMargin;
protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
{
base.PrepareContainerForItemOverride(element, item);
OnPrepareContainerForItem(new PrepareContainerForItemEventArgs(element, item));
if ((InnerMargin.Top > 0.0 || InnerMargin.Bottom > 0.0))
{
if (Items.IndexOf(item) == Items.Count - 1) // is last element of list
{
if (lastElement != element) // margin not already set
{
if (lastElement != null)
lastElement.Margin = lastElementMargin;
lastElement = (FrameworkElement)element;
lastElementMargin = lastElement.Margin;
UpdateLastItemMargin();
}
}
else if (lastElement == element) // if last element is recycled it appears inside the list => reset margin
{
lastElement.Margin = lastElementMargin;
lastElement = null;
}
}
}
PrepareContainerForItem
事件,一个属性和
IsScrolling
的事件(还有一个扩展的
LowProfileImageLoader
和
IsSuspended
属性,可以在
IsScrolling
事件中设置以提高滚动平滑度。 ..) 和新属性
InnerMargin
用于描述的问题...
关于silverlight - 虚拟化 ListBox 的 ItemsControl 的边距无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8008929/
假设我有一系列值: Customer | Services | Cost | Paid Mel | Abc | $1.00 | TRUE Mel | Def
我试图让 ListBox 中的项目跨越 ListBox 的整个宽度。我发现了几篇处理 HorizontalContentAlignment="Stretch"的帖子,但我无法让它在我的 WP7 应
我有一个 ListBox,所以我可以使用绑定(bind)。我是 Silverlight 的新手,所以也许还有另一种方法。我只想在模板中显示项目列表。我不需要它是可缩放的,因为它适合屏幕。这是马代码:
我有一个带有多列列表框和组合框的用户窗体。 ListBox 默认显示完整的数据集。 ComboBox 包含来自 ListBox 中某一列的值。从 ComboBox 中选择一个值会过滤 ListBox
我使用以下方法将目录枚举到 ListBox 中: private void TE_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
我有一个列表框,每个列表项中都有一堆控件。
我有 2 个列表框,如果您单击顶部的一个项目,那么底部的一个会过滤到一些结果。 我正在尝试学习 WPF 和 MVVM,并且想知道这是否是正确的方法。这是最好的方法吗? 这是我所做的: class Vi
我的原型(prototype)显示包含“页面”的“文档”由缩略图表示。每个文档可以有任意数量的页面。例如,可能有1000 个文档,每个文档 5 页,或 5 个文档,每个文档 1000 页每个,或介于两
假设我需要显示一个包含大量记录的列表,哪个控件更好?或者说,哪个控件的滚动体验更好? 我看到很多人报告了这个 LongListSelector 的问题,它真的有太多问题而无法使用吗? 希望有人能为我阐
我想在双击列表框中的项目时创建视觉效果。到目前为止,我具有拖放功能,其中项目在视觉上附加到鼠标,并且可以移动到放置目标。通过该功能,我可以使用获取项目容器的相同逻辑为项目设置动画,但是我无法离开项目控
我想在 dataTemplate 中使用 dataTemplale。我想像这样在列表框中显示数据: 这就是我得到的。它不起作用。 cl
如果这些值存在于另一个 ListBox 中,我将尝试从 ListBox 中删除数字项。我的代码似乎不起作用,而且我无法在线找到任何帮助。 ListBox1 由 Array 填充,ListBox2 由
是否可以在 C# 中将 ListBox.SelectedObjectCollection 转换为 ListBox.ObjectCollection?如果是这样,我该怎么做? 最佳答案 我有一个接受 L
我正在开发一个 WinForms 项目,其中有一个 TextBox用户可以在其中输入搜索查询,以及 ListBox其中所有项目都是可见的,并且匹配的项目突出显示。 当我遍历 ListBox.Items
除了一个问题,我手头的任务几乎完成了。我正在尝试通过 beginupdate() 和 endupdate() 通过 backgroundWorker 线程控制列表框 ui 的更新,该线程也用于更新我的
我有一个 Windows 窗体应用程序,在同一个窗体上有两个 ListBox 控件。他们都将 SelectionMode 设置为“MultiExtended”。 当我改变其中一个的选择时,其他的选择也
我正在动态创建一个 Winforms 多选列表框并将其添加到流程面板控件中。我从我创建的对象绑定(bind)了一个数据源,并验证了 DataSource 实际上确实有大约 14 个元素。当我执行 li
我想让 ListItems 的橙色背景扩展到列表框的整个宽度。 目前它们的宽度仅为名字 + 姓氏。 我已将所有元素设置为:HorizontalAlignment="Stretch"。 我希望 Li
我有一个带有自定义模板的普通列表框来显示项目。我无法管理的是在列表框的整个宽度上水平拉伸(stretch)模板。 我的问题是,主窗口中的所有元素都是动态放置的,并且它们会随着窗口大小更改方法的大小而调
嗯,嗯,这意味着一些行的大小应该是两行的。我的老板认为这是更简单的解决方案,而不是将显示的文本限制为适合宽度并且不喜欢水平滚动条 >_< 最佳答案 lst.DrawMode = System.Wind
我是一名优秀的程序员,十分优秀!