我有一个带有多个ListView控件的应用程序,其中要求ListView中的项目必须完全可见.应该永远不会在列表中显示部分ListViewItem.如果用户在最终显示部分项目的位置释放ScrollViewer,则列表应"快照"并自行更正,以便仅显示完整项目.
有没有人这样做过?我想我需要重载ListView和/或ScrollViewer才能执行此操作.我正在寻找有关如何处理此问题的建议.谢谢.
这是我的一个清单:
<ctrls:SnapList x:Name="PART_ProductList"
ScrollViewer.CanContentScroll="False"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ScrollViewer.HorizontalScrollBarVisibility="Hidden"
ItemContainerStyle="{StaticResource ProductFinderItem}"
Canvas.Top="373" Canvas.Left="75"
Height="910" Width="900" >
<ctrls:SnapList.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Standard" />
</ItemsPanelTemplate>
</ctrls:SnapList.ItemsPanel>
<ctrls:SnapList.Template>
<ControlTemplate>
<ScrollViewer x:Name="Scroller" VerticalAlignment="Top" CanContentScroll="True" Style="{StaticResource VertScrollViewer}" Focusable="false" >
<ItemsPresenter />
</ScrollViewer>
</ControlTemplate>
</ctrls:SnapList.Template>
</ctrls:SnapList>
Run Code Online (Sandbox Code Playgroud) 好的,这是我的代码.请注意,StackPanel直接位于UserControl中.
<UserControl>
<StackPanel Orientation="Horizontal">
<ScrollViewer Width="450"
VerticalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Disabled">
<Rectangle Width="400" Height="4000" Fill="BlanchedAlmond"/>
</ScrollViewer>
<ScrollViewer VerticalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Disabled">
<ItemsControl BorderBrush="Green"
BorderThickness="2"
ItemsSource="{Binding Path=MyObservableCollection}"
ItemTemplate="{StaticResource FatTemplate}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</ScrollViewer>
</StackPanel>
</UserControl>
Run Code Online (Sandbox Code Playgroud)
(代码已编辑)
请注意,矩形就在那里,因为该滚动查看器的内容无关紧要.
问题是WrapPanel只是水平扩展而不包裹......
我找到了一些解决方案:
为WrapPanel提供绝对宽度(但随后窗口不会调整大小).
将宽度绑定到其父宽度 - ItemsControl或ScrollViewer(ScrollViewer在像这样的有限情况下工作得更好).
Width="{Binding RelativeSource=
{RelativeSource FindAncestor,
AncestorType={x:Type ScrollViewer}},
Path=ActualWidth}"
Run Code Online (Sandbox Code Playgroud)这种技术的问题在于,如果一个控件在StackPanel或Grid旁边,你需要将它绑定到它的父级大小减去旁边的控件.然后是艰难的东西.我构建了一个转换器,它对接收的数字应用数学运算,因此我可以从父宽度中减去给定的宽度:
Width="{Binding RelativeSource=
{RelativeSource FindAncestor,
AncestorType={x:Type UserControl}},
Path=ActualWidth,
Converter={StaticResource Convertisseur_Size_WXYZ},
ConverterParameter=-260}"
Run Code Online (Sandbox Code Playgroud)
但是,由于您无法绑定传递给ConverterParameter的值,
ConverterParameter={Binding ...} (doesn't work)
Run Code Online (Sandbox Code Playgroud)
我想要:
什么是更好的解决方案?
注意:如果有任何不清楚的地方,我可以添加细节.
我没有使用DataGrid或ListView,而是使用ScrollViewer和Grids来创建包含每个单元格列的项目包装面板的单元格.
我想要一个与datagrid或listview的标题列类似的行为,以便在垂直滚动它下面的项目时保持冻结,但让它水平滚动.
我目前有以下作为我的主窗口的根目录,除了当显示垂直滚动条时,项目的对齐关闭.
笔记:
因此,当"innerScrollViewer"显示其垂直滚动条时,项目不再与外部列标题对齐,并且由于右侧垂直滚动条,项目将向左移动.如何在显示垂直滚动条的两种情况下使用外部列标题动态排列内容?
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled">
<Grid x:Name="mainGrid"
Width="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ScrollViewer}}, Path=ViewportWidth}">
<RowDefinitions>
<RowDefinition Height="Auto" /> <!-- Contains Header columns dynamically added to be "frozen" -->
<RowDefinition Height="*" /> <!-- "row groupings" -->
</RowDefinitions>
<ScrollViewer x:Name="innerScrollViewer"
HorizontalScrollBarVisibility="Disabled"
VerticalScrollBarVisibility="Auto"
Grid.Row="1"
Grid.ColumnSpan="{Binding Path=NumColumns}">
<ItemsControl Name="mainWorkItemsItemsControl"
Width="{Binding ActualWidth, ElementName=mainGrid}"
ItemsSource="{Binding MyGroups}"
ItemTemplate="{StaticResource groupedTemplate}" />
</ScrollViewer>
</Grid>
</ScrollViewer>
<DataTemplate x:Key="groupedTemplate">
<ItemsControl ItemsSource="{Binding GroupItems}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<!-- Creates a grid with one row and the same number of …Run Code Online (Sandbox Code Playgroud) 在WPF中,我有以下XAML:
<ScrollViewer Canvas.Left="2266" Canvas.Top="428" Height="378" Name="scrollViewer1" Width="728" PanningMode="VerticalOnly" PanningRatio="2">
<Canvas Height="1732.593" Width="507.667">
<Slider Height="40.668" x:Name="slider1" Width="507.667" Style="{DynamicResource SliderStyle1}" Canvas.Left="15" Canvas.Top="150" />
</Slider>
</Canvas>
</ScrollViewer>
Run Code Online (Sandbox Code Playgroud)
这是一个包含Slider的ScrollViewer.我在触摸屏上使用以下内容,我甚至使用平移来垂直滚动ScrollViewer.设置PanningMode ="VerticalOnly"时,滑块停止工作!
我假设ScollViewer正在使用touch\slide事件并在滑块之前处理它(但我认为我在这方面错了).
这有什么解决方法吗?
我目前正在使用Metro和C#为Windows 8编写应用程序.在我的应用程序中,我使用scrollviewer和gridview的组合来显示我的数据.不过我的问题是,如何用鼠标滚轮滚动它?
在我的搜索中,我发现MouseWheelParameters位于System.Windows.Input中,但是当我尝试使用get_pageTranslation时,它会给出一个错误,指出我无法显式使用get方法.
使用固定标题创建ScrollViewer的最简单方法是什么(控件始终位于顶部,忽略滚动),但仍然水平滚动.
我应该使用ScrollContentPresenter上方的标题编写自己的ScrollViewer模板,并在水平滚动值更改时移动它,或者最好将标题放在ScrollViewer中并垂直移动它?或者可能有更好的方法来实现这一目标......
我创建了一个基于Grid(而不是DataGrid)的用户控件,它包含在ScrollViewer中.现在我想像DataGrid一样拥有冻结的行/列功能,但无法弄清楚如何.
有人可以告诉我一些如何在WPF DataGrid中完成它吗?
我在平板电脑华硕ME400 Intel Atom Z2760上运行我的桌面应用程序WPF.所有工作都正常,但是当我使用scrollviewer时,用手指在滚动结束时用手指滚动移动(简化平移模式horizontalOnly),窗口移动,你会看到任务栏片刻.如果我用手指滚动,直到在滚动条中建立后才会看到效果.
我怎么能避免这个窗口运动?当我在滚动条的末尾滚动时,如何锁定窗口并且不允许移动?
我的目标是在WPF中模拟"无限滚动" ListView.我用一些不太理想的方法完成了这项任务,我确信有更好的方法.
通过"无限滚动"我的意思是:
让我们说一个ListView有20个项目(有序1, 2, 3, 4, ... 17, 18, 19, 20).当用户向下滚动一个项目时,该项目顶部的项目ListView被移除并放置在项目的结尾处,ListView因此项目的顺序是2, 3, 4, 5, ... 18, 19, 20, 1.现在,如果用户向下滚动两个项目,则前两个项目将被移除并放置在最后,因此项目的顺序为4, 5, 6, 7, ... 20, 1, 2, 3.现在,类似地,如果用户向上滚动一个项目,则将其底部的项目ListView移除并放置在开头,以便项目的顺序为3, 4, 5, 6, ... 19, 20, 1, 2.
我已经实现这个任务与分配给下面的功能ScrollChanged的情况下,ScrollViewer我希望是"无限":
// sv - the ScrollViewer to which this event handler is listening
// lv - the ListView associated with "sv"
bool handle_scroll …Run Code Online (Sandbox Code Playgroud) 这就是我要的:
1.)当我单击我的Expander按钮并展开它时,它应该延伸到Grid的末尾
见样本图像=> 
2.)当我在Expander ScrollBars中的RichTextBox中写入更多文本而不是空格时,必须可见,我应该能够向下滚动.
将滚动查看器放在Expander内容周围并不难,但即使设置"自动"它们也永远不会出现也无济于事.将滚动查看器设置为"可见"我无法滚动,因为扩展器的内容无休止地下降.
这是我的示例代码:
<Grid Margin="30,0,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="30" />
<RowDefinition Height="*" />
<RowDefinition Height="30" />
</Grid.RowDefinitions>
<StackPanel Background="LightCoral" Orientation="Horizontal">
<TextBlock Grid.Column="0" Text="Incident type:" VerticalAlignment="Center" />
<ComboBox Grid.Column="1" IsEditable="True" Margin="0,7" Text="{Binding SelectedIncidentReport.IncidentType,Mode=TwoWay}" />
<TextBlock Grid.Column="0" Grid.Row="1" Text="Teachers name:" VerticalAlignment="Center" />
<TextBox Grid.Column="1" Grid.Row="1" Height="25" Text="{Binding SelectedIncidentReport.TeacherName,Mode=TwoWay}" />
<TextBlock Grid.Column="0" Grid.Row="2" Text="Tutor group:" VerticalAlignment="Center" />
<TextBox Grid.Column="1" Grid.Row="2" Margin="0,7" Text="{Binding SelectedIncidentReport.TutorGroup,Mode=TwoWay}" />
</StackPanel>
<Grid Background="LightBlue" Grid.Row="1" >
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition …Run Code Online (Sandbox Code Playgroud) scrollviewer ×10
wpf ×9
c# ×3
.net ×2
listview ×2
windows-8 ×2
components ×1
datagrid ×1
expander ×1
grid ×1
mouse ×1
multi-touch ×1
scroll ×1
scrollview ×1
slider ×1
stretch ×1
wrappanel ×1
xaml ×1