wpf 自定义scrollviewer

http://www.codeproject.com/Tips/115159/Silverlight-Tip-ScrollViewer-for-a-WrapPanel


of sssssssssssssssssssssssscouse,


scrollview can do this


but, after using iphone and android


everyone konw this is absolutly not enough


在WPF,自定义控件,属性,什么都没搞懂的情况下

靠网上找的源码,写了一个

比计划中早完成

-->自定义WPF ScrollViewer-仿iphone

 

哈哈,不过方向调转了=、=、

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
WPF中,可以通过继承ComboBox类并重写其默认模板,来实现自定义ComboBox的样式和行为。下面是一个简单的例子,演示如何创建一个带有自定义下拉框项的ComboBox。 首先,创建一个名为CustomComboBox的类,继承自ComboBox。然后,在类的构造函数内部,通过调用DefaultStyleKey属性,并传递ComboBox类型,来指定ComboBox的默认样式。 ```csharp public class CustomComboBox : ComboBox { public CustomComboBox() { DefaultStyleKey = typeof(ComboBox); } } ``` 接下来,需要定义ComboBox的模板。在模板中,我们可以指定ComboBox的各个部分的样式和行为。 ```xml <Style TargetType="{x:Type local:CustomComboBox}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type local:CustomComboBox}"> <Grid> <ToggleButton x:Name="PART_ToggleButton" Grid.Column="2" Focusable="false" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" ClickMode="Press"> <ToggleButton.Template> <ControlTemplate TargetType="{x:Type ToggleButton}"> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition/> <ColumnDefinition Width="20"/> </Grid.ColumnDefinitions> <Border x:Name="Border" Grid.ColumnSpan="2" CornerRadius="4" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"/> <Path x:Name="Arrow" Grid.Column="1" Fill="{TemplateBinding Foreground}" HorizontalAlignment="Center" VerticalAlignment="Center" Data="M 0 0 L 4 4 L 8 0 Z"/> </Grid> </ControlTemplate> </ToggleButton.Template> </ToggleButton> <ContentPresenter x:Name="PART_ContentPresenter" Margin="5, 0, 0, 0" HorizontalAlignment="Left" VerticalAlignment="Center" ContentSource="SelectedItem" RecognizesAccessKey="True"/> <Popup x:Name="PART_Popup" AllowsTransparency="true" IsOpen="{TemplateBinding IsDropDownOpen}" Placement="Bottom" Focusable="false"> <Grid x:Name="DropDown" SnapsToDevicePixels="true" MinWidth="{TemplateBinding ActualWidth}" MaxHeight="200"> <Border x:Name="DropDownBorder" Background="{StaticResource {x:Static SystemColors.WindowBrushKey}}" BorderThickness="1" BorderBrush="{StaticResource {x:Static SystemColors.ActiveBorderBrushKey}}"/> <ScrollViewer Margin="4,6,4,6" SnapsToDevicePixels="true"> <StackPanel IsItemsHost="true" KeyboardNavigation.DirectionalNavigation="Contained"/> </ScrollViewer> </Grid> </Popup> </Grid> </ControlTemplate> </Setter.Value> </Setter> </Style> ``` 在模板中,我们使用了一个ToggleButton来控制下拉框的打开关闭。另外,使用了一个ContentPresenter来展示选中的项,在Popup中使用了一个StackPanel来展示下拉框选项。 最后,使用CustomComboBox来创建自定义ComboBox,并添加下拉框选项。 ```xml <local:CustomComboBox Width="150"> <ComboBoxItem>Item 1</ComboBoxItem> <ComboBoxItem>Item 2</ComboBoxItem> <ComboBoxItem>Item 3</ComboBoxItem> </local:CustomComboBox> ``` 这样,就可以创建一个具有自定义下拉框项的ComboBox了。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

avi9111

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值