WPF,请问ListBox的标准模板

离开几句话 2013-07-18 10:42:06
请看ListBox的标准模板:
MSDN


问题:
里面的ScrollViewer,没有指定引用哪个资源呢?
...全文
216 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
离开几句话 2013-07-19
  • 打赏
  • 举报
回复
引用 7 楼 MicrosoftCenterOfHN 的回复:
ScrollViewer是这个组合控件中的一部分,这个ScrollViewer控件已经定义好了。可以直接用,而这里面正好也不需要什么特殊的样式,默认的就可以了。 模板里面还有一个StackPanel,不也是没什么特殊样式吗?默认的就足够了。
默认的滚动条很难看。如果要改变滚动条,是不是把ScrollViewer指向新的模板,引用资源,是吗?
  • 打赏
  • 举报
回复
ScrollViewer是这个组合控件中的一部分,这个ScrollViewer控件已经定义好了。可以直接用,而这里面正好也不需要什么特殊的样式,默认的就可以了。 模板里面还有一个StackPanel,不也是没什么特殊样式吗?默认的就足够了。
E次奥 2013-07-19
  • 打赏
  • 举报
回复
ScrollViewer本来就是滚动条,所以你可以看下他的样式.
离开几句话 2013-07-19
  • 打赏
  • 举报
回复
引用 1 楼 sp1234 的回复:
<ScrollViewer Focusable="false" Padding="{TemplateBinding Padding}"> <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/> </ScrollViewer> [/code]
你这个ScrollViewer,不引用资源吗?那应该是什么样的滚动条样式呢?
离开几句话 2013-07-19
  • 打赏
  • 举报
回复
ScrollViewer也有模板和样式吧,我说的是,在ListBox模板中不是要使用ScrollViewer吗,我给出的MSDN链接可以看出ListBox标准模板中,对ScrollViewer并没有引用资源啊,
  • 打赏
  • 举报
回复
引用 9 楼 u011447395 的回复:
[quote=引用 7 楼 MicrosoftCenterOfHN 的回复:] ScrollViewer是这个组合控件中的一部分,这个ScrollViewer控件已经定义好了。可以直接用,而这里面正好也不需要什么特殊的样式,默认的就可以了。 模板里面还有一个StackPanel,不也是没什么特殊样式吗?默认的就足够了。
默认的滚动条很难看。如果要改变滚动条,是不是把ScrollViewer指向新的模板,引用资源,是吗?[/quote] 如果要改变的话,那我觉得你得重写ListBox的模板了。
离开几句话 2013-07-18
  • 打赏
  • 举报
回复
引用 2 楼 guwei4037 的回复:
ScrollViewer就是一个滚动条容器,不需要引用color资源。
我是说,滚动条也有滚动条的样式吧,ListBox的滚动条样式到底是哪种,不引用吗?也就是ScrollViewer
全栈极简 2013-07-18
  • 打赏
  • 举报
回复
ScrollViewer就是一个滚动条容器,不需要引用color资源。
  • 打赏
  • 举报
回复
我使用 Blend for vs2012创建一个空的窗体,然后拖入一个ListBox,然后点击鼠标右键->编辑模板->复制模板,之后Blend给出的ListBox模板代码跟你说的是不同的:
<Window x:Class="WpfApplication5.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
	<Window.Resources>
		<SolidColorBrush x:Key="ListBox.Static.Background" Color="#FFFFFFFF"/>
		<SolidColorBrush x:Key="ListBox.Static.Border" Color="#FFABADB3"/>
		<SolidColorBrush x:Key="ListBox.Disabled.Background" Color="#FFFFFFFF"/>
		<SolidColorBrush x:Key="ListBox.Disabled.Border" Color="#FFD9D9D9"/>
		<Style x:Key="ListBoxStyle1" TargetType="{x:Type ListBox}">
			<Setter Property="Background" Value="{StaticResource ListBox.Static.Background}"/>
			<Setter Property="BorderBrush" Value="{StaticResource ListBox.Static.Border}"/>
			<Setter Property="BorderThickness" Value="1"/>
			<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
			<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
			<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
			<Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
			<Setter Property="ScrollViewer.PanningMode" Value="Both"/>
			<Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
			<Setter Property="VerticalContentAlignment" Value="Center"/>
			<Setter Property="Template">
				<Setter.Value>
					<ControlTemplate TargetType="{x:Type ListBox}">
						<Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="1" SnapsToDevicePixels="true">
							<ScrollViewer Focusable="false" Padding="{TemplateBinding Padding}">
								<ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
							</ScrollViewer>
						</Border>
						<ControlTemplate.Triggers>
							<Trigger Property="IsEnabled" Value="false">
								<Setter Property="Background" TargetName="Bd" Value="{StaticResource ListBox.Disabled.Background}"/>
								<Setter Property="BorderBrush" TargetName="Bd" Value="{StaticResource ListBox.Disabled.Border}"/>
							</Trigger>
							<MultiTrigger>
								<MultiTrigger.Conditions>
									<Condition Property="IsGrouping" Value="true"/>
									<Condition Property="VirtualizingPanel.IsVirtualizingWhenGrouping" Value="false"/>
								</MultiTrigger.Conditions>
								<Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
							</MultiTrigger>
						</ControlTemplate.Triggers>
					</ControlTemplate>
				</Setter.Value>
			</Setter>
		</Style>
	</Window.Resources>
    <Grid>
    	<ListBox HorizontalAlignment="Left" Height="100" VerticalAlignment="Top" Width="100" Style="{DynamicResource ListBoxStyle1}"/>
        
    </Grid>
</Window>

111,121

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧