一、ComboBox基本样式

ComboBox有两种状态,可编辑和不可编辑状态。通过设置IsEditable属性可以切换控件状态。

先看基本样式效果:

基本样式代码如下:

  1. <!--ComboBox-->
  2. <!--ComBoBox项选中背景色-->
  3. <SolidColorBrush x:Key="ComboBoxSelectdBackground" Color="#ff8c69"/>
  4. <!--ComBoBox项鼠标经过背景色-->
  5. <SolidColorBrush x:Key="ComboBoxMouseOverBackground" Color="#ff3030"/>
  6. <!--ComBoBox项选中前景色-->
  7. <SolidColorBrush x:Key="ComboBoxSelectedForeground" Color="White"/>
  8. <!--ComBoBox项鼠标经过前景色-->
  9. <SolidColorBrush x:Key="ComboBoxMouseOverForegrond" Color="White"/>
  10. <Style TargetType="{x:Type ComboBox}">
  11. <Setter Property="ItemContainerStyle">
  12. <Setter.Value>
  13. <Style TargetType="ComboBoxItem">
  14. <Setter Property="Height" Value="20"/>
  15. <Setter Property="Template">
  16. <Setter.Value>
  17. <ControlTemplate TargetType="{x:Type ComboBoxItem}">
  18. <Grid Height="{TemplateBinding Height}" Width="{TemplateBinding Width}">
  19. <Border x:Name="_borderbg" Background="Transparent"/>
  20. <TextBlock Margin="3 0 3 0" VerticalAlignment="Center" x:Name="_txt" Foreground="#333" Text="{Binding Content,RelativeSource={RelativeSource TemplatedParent}}"/>
  21. <Border x:Name="_border" Background="White" Opacity="0"/>
  22. </Grid>
  23. <ControlTemplate.Triggers>
  24. <Trigger Property="IsSelected" Value="true">
  25. <Setter TargetName="_borderbg" Property="Background" Value="{StaticResource ComboBoxSelectdBackground}" />
  26. <Setter TargetName="_txt" Property="Foreground" Value="{StaticResource ComboBoxSelectedForeground}"/>
  27. </Trigger>
  28. <MultiTrigger>
  29. <MultiTrigger.Conditions>
  30. <Condition Property="IsSelected" Value="false"/>
  31. <Condition Property="IsMouseOver" Value="true"/>
  32. </MultiTrigger.Conditions>
  33. <Setter TargetName="_borderbg" Property="Background" Value="{StaticResource ComboBoxMouseOverBackground}" />
  34. <Setter TargetName="_txt" Property="Foreground" Value="{StaticResource ComboBoxMouseOverForegrond}"/>
  35. </MultiTrigger>
  36.  
  37. </ControlTemplate.Triggers>
  38. </ControlTemplate>
  39. </Setter.Value>
  40. </Setter>
  41. </Style>
  42. </Setter.Value>
  43. </Setter>
  44. <Setter Property="Template">
  45. <Setter.Value>
  46. <ControlTemplate TargetType="{x:Type ComboBox}">
  47. <Grid>
  48.  
  49. <Grid.ColumnDefinitions>
  50. <ColumnDefinition Width="0.7*"/>
  51. <ColumnDefinition Width="0.3*" MaxWidth="30"/>
  52. </Grid.ColumnDefinitions>
  53. <Border Grid.Column="0" Grid.ColumnSpan="2" BorderThickness="1" BorderBrush="{TemplateBinding BorderBrush}" CornerRadius="1,0,0,1"/>
  54. <ContentPresenter HorizontalAlignment="Left" Margin="3,3,0,3" x:Name="ContentSite" VerticalAlignment="Center" Content="{TemplateBinding SelectionBoxItem}" ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}" IsHitTestVisible="False"/>
  55.  
  56. <!--ToggleButton 已数据绑定到 ComboBox 本身以切换 IsDropDownOpen-->
  57. <ToggleButton Grid.Column="0" Grid.ColumnSpan="2" Template="{StaticResource ComboBoxToggleButton}" x:Name="ToggleButton" Focusable="false" IsChecked="{Binding Path=IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" ClickMode="Press"/>
  58. <!--必须将 TextBox 命名为 PART_EditableTextBox,否则 ComboBox 将无法识别它-->
  59. <TextBox Visibility="Hidden" BorderThickness="0" Margin="2 0 0 0" x:Name="PART_EditableTextBox" VerticalAlignment="Center" Focusable="True" Background="Transparent" IsReadOnly="{TemplateBinding IsReadOnly}"/>
  60.  
  61. <!--Popup 可显示 ComboBox 中的项列表。IsOpen 已数据绑定到通过 ComboBoxToggleButton 来切换的 IsDropDownOpen-->
  62. <Popup IsOpen="{TemplateBinding IsDropDownOpen}" Placement="Bottom" x:Name="Popup" Focusable="False" AllowsTransparency="True" PopupAnimation="Slide">
  63. <Grid MaxHeight="150" MinWidth="{TemplateBinding ActualWidth}" x:Name="DropDown" SnapsToDevicePixels="True">
  64. <Border x:Name="DropDownBorder" BorderBrush="#e8e8e8" BorderThickness="1 0 1 1"/>
  65. <ScrollViewer Margin="1" SnapsToDevicePixels="True" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" CanContentScroll="True">
  66. <!--StackPanel 用于显示子级,方法是将 IsItemsHost 设置为 True-->
  67. <StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Contained" Background="White"/>
  68. </ScrollViewer>
  69. </Grid>
  70. </Popup>
  71. </Grid>
  72. <ControlTemplate.Triggers>
  73. <Trigger Property="IsEditable" Value="true">
  74. <Setter TargetName="PART_EditableTextBox" Property="Visibility" Value="Visible" />
  75. </Trigger>
  76. </ControlTemplate.Triggers>
  77. </ControlTemplate>
  78. </Setter.Value>
  79. </Setter>
  80. </Style>

引用示例:

  1. <ComboBox x:Name="combobox" Width="150" Margin="10" IsEditable="False" BorderBrush="#e8e8e8">
  2. <CheckBox Content="上海" Tag="1"></CheckBox>
  3. <CheckBox Content="北京" Tag="2"></CheckBox>
  4. <CheckBox Content="天津" Tag="3"></CheckBox>
  5. <CheckBox Content="广州" Tag="4"></CheckBox>
  6. </ComboBox>

二、ComboBox扩展样式(多选控件)

ComBoBox能够单选选择数据,那么能不能实现多选的操作呢,答案是肯定的。这里多选的自定义控件参考了博主“梦里花落知多少”的内容。我对样式做了补充,使其能够更方便的进行移除多选的内容。同时也更好的展示了已选的内容,大家可以根据实际需求做出更好的展示效果。

先看效果:

2.1、添加自定义控件MultiComboBox

  1. public class MultiComboBox : ComboBox
  2. {
  3. static MultiComboBox()
  4. {
  5. DefaultStyleKeyProperty.OverrideMetadata(typeof(MultiComboBox), new FrameworkPropertyMetadata(typeof(MultiComboBox)));
  6. }
  7.  
  8. private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
  9. {
  10. d.SetValue(e.Property, e.NewValue);
  11. }
  12.  
  13. /// <summary>
  14. /// 选中项列表
  15. /// </summary>
  16. public ObservableCollection<MultiCbxBaseData> ChekedItems
  17. {
  18. get { return (ObservableCollection<MultiCbxBaseData>)GetValue(ChekedItemsProperty); }
  19. set { SetValue(ChekedItemsProperty, value); }
  20. }
  21.  
  22. public static readonly DependencyProperty ChekedItemsProperty =
  23. DependencyProperty.Register("ChekedItems", typeof(ObservableCollection<MultiCbxBaseData>), typeof(MultiComboBox), new PropertyMetadata(new ObservableCollection<MultiCbxBaseData>(), OnPropertyChanged));
  24.  
  25. /// <summary>
  26. /// ListBox竖向列表
  27. /// </summary>
  28. private ListBox _ListBoxV;
  29.  
  30. /// <summary>
  31. /// ListBox横向列表
  32. /// </summary>
  33. private ListBox _ListBoxH;
  34.  
  35. public override void OnApplyTemplate()
  36. {
  37. base.OnApplyTemplate();
  38. _ListBoxV = Template.FindName("PART_ListBox", this) as ListBox;
  39. _ListBoxH = Template.FindName("PART_ListBoxChk", this) as ListBox;
  40. _ListBoxH.ItemsSource = ChekedItems;
  41. _ListBoxV.SelectionChanged += _ListBoxV_SelectionChanged;
  42. _ListBoxH.SelectionChanged += _ListBoxH_SelectionChanged;
  43.  
  44. if (ItemsSource != null)
  45. {
  46. foreach (var item in ItemsSource)
  47. {
  48. MultiCbxBaseData bdc = item as MultiCbxBaseData;
  49. if (bdc.IsCheck)
  50. {
  51. _ListBoxV.SelectedItems.Add(bdc);
  52. }
  53. }
  54. }
  55. }
  56.  
  57. private void _ListBoxH_SelectionChanged(object sender, SelectionChangedEventArgs e)
  58. {
  59. foreach (var item in e.RemovedItems)
  60. {
  61. MultiCbxBaseData datachk = item as MultiCbxBaseData;
  62.  
  63. for (int i = ; i < _ListBoxV.SelectedItems.Count; i++)
  64. {
  65. MultiCbxBaseData datachklist = _ListBoxV.SelectedItems[i] as MultiCbxBaseData;
  66. if (datachklist.ID == datachk.ID)
  67. {
  68. _ListBoxV.SelectedItems.Remove(_ListBoxV.SelectedItems[i]);
  69. }
  70. }
  71. }
  72. }
  73.  
  74. void _ListBoxV_SelectionChanged(object sender, SelectionChangedEventArgs e)
  75. {
  76. foreach (var item in e.AddedItems)
  77. {
  78. MultiCbxBaseData datachk = item as MultiCbxBaseData;
  79. datachk.IsCheck = true;
  80. if (ChekedItems.IndexOf(datachk) < )
  81. {
  82. ChekedItems.Add(datachk);
  83. }
  84. }
  85.  
  86. foreach (var item in e.RemovedItems)
  87. {
  88. MultiCbxBaseData datachk = item as MultiCbxBaseData;
  89. datachk.IsCheck = false;
  90. ChekedItems.Remove(datachk);
  91. }
  92. }
  93.  
  94. public class MultiCbxBaseData
  95. {
  96. private int _id;
  97. /// <summary>
  98. /// 关联主键
  99. /// </summary>
  100. public int ID
  101. {
  102. get { return _id; }
  103. set { _id = value; }
  104. }
  105.  
  106. private string _viewName;
  107. /// <summary>
  108. /// 显示名称
  109. /// </summary>
  110. public string ViewName
  111. {
  112. get { return _viewName; }
  113. set
  114. {
  115. _viewName = value;
  116. }
  117. }
  118.  
  119. private bool _isCheck;
  120. /// <summary>
  121. /// 是否选中
  122. /// </summary>
  123. public bool IsCheck
  124. {
  125. get { return _isCheck; }
  126. set { _isCheck = value;}
  127. }
  128. }
  129. }

2.2、定义MultiComboBox控件的样式

  1. <ControlTemplate x:Key="ComboBoxToggleButton" TargetType="{x:Type ToggleButton}">
  2. <Grid Height="25">
  3. <Border Grid.Column="1" Background="White" Opacity="0" Cursor="Hand"/>
  4. <Path x:Name="Arrow" Grid.Column="1" Data="M 0 0 6 6 12 0 Z" VerticalAlignment="Center" HorizontalAlignment="Center" Stretch="None" Fill="#B1B1B1" />
  5. </Grid>
  6. <ControlTemplate.Triggers>
  7. <Trigger Property="IsChecked" Value="true">
  8. <Setter TargetName="Arrow" Property="RenderTransform">
  9. <Setter.Value>
  10. <RotateTransform CenterX="6" CenterY="3" Angle="180"></RotateTransform>
  11. </Setter.Value>
  12. </Setter>
  13. <Setter TargetName="Arrow" Property="Margin" Value="0 0 0 2"/>
  14. </Trigger>
  15. </ControlTemplate.Triggers>
  16. </ControlTemplate>
  17.  
  18. <!--MultiComboBox普通样式-->
  19. <Style TargetType="{x:Type local:MultiComboBox}">
  20. <Setter Property="Width" Value="200" />
  21. <Setter Property="HorizontalContentAlignment" Value="Stretch" />
  22. <Setter Property="VerticalContentAlignment" Value="Center" />
  23. <Setter Property="SnapsToDevicePixels" Value="True" />
  24. <Setter Property="MaxDropDownHeight" Value="400" />
  25. <Setter Property="Template">
  26. <Setter.Value>
  27. <ControlTemplate TargetType="{x:Type local:MultiComboBox}">
  28. <Grid>
  29. <Border x:Name="Bg" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}" BorderBrush="#eaeaea" BorderThickness="1" >
  30. <Grid x:Name="PART_Root">
  31.  
  32. <Grid x:Name="PART_InnerGrid" Margin="0">
  33. <Grid.ColumnDefinitions>
  34. <ColumnDefinition Width="*" />
  35. <ColumnDefinition Width="0.3*" MaxWidth="30" />
  36. </Grid.ColumnDefinitions>
  37. <ListBox x:Name="PART_ListBoxChk" SelectionMode="Multiple" BorderThickness="0" ScrollViewer.VerticalScrollBarVisibility="Disabled">
  38. <ListBox.ItemsPanel>
  39. <ItemsPanelTemplate>
  40. <VirtualizingStackPanel Orientation="Horizontal" VirtualizingStackPanel.IsVirtualizing="True" />
  41. </ItemsPanelTemplate>
  42. </ListBox.ItemsPanel>
  43. <ListBox.ItemContainerStyle>
  44. <Style TargetType="ListBoxItem">
  45. <Setter Property="BorderThickness" Value="0"/>
  46. <Setter Property="IsSelected" Value="True"/>
  47. <Setter Property="Template">
  48. <Setter.Value>
  49. <ControlTemplate TargetType="ListBoxItem">
  50. <CheckBox BorderThickness="0" VerticalAlignment="Center" HorizontalAlignment="Center" Content="{Binding ViewName}" IsChecked="{Binding Path=IsSelected,RelativeSource={RelativeSource TemplatedParent},Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"/>
  51. </ControlTemplate>
  52. </Setter.Value>
  53. </Setter>
  54. </Style>
  55. </ListBox.ItemContainerStyle>
  56. </ListBox>
  57.  
  58. <!--下拉按钮-->
  59. <ToggleButton x:Name="PART_DropDownToggle" IsTabStop="False"
  60. IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
  61. Grid.Column="1" Template="{StaticResource ComboBoxToggleButton}" />
  62. </Grid>
  63. </Grid>
  64. </Border>
  65. <!--弹出多选列表-->
  66. <Popup x:Name="PART_Popup" AllowsTransparency="True" Focusable="False" StaysOpen="False"
  67. IsOpen="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}"
  68. PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Placement="Bottom">
  69. <Grid Width="{Binding ActualWidth, RelativeSource={RelativeSource TemplatedParent}}" MaxHeight="{Binding MaxDropDownHeight, RelativeSource={RelativeSource TemplatedParent}}" >
  70. <ListBox x:Name="PART_ListBox" SelectionMode="Multiple" BorderThickness="1 0 1 1" Background="White" ItemsSource="{Binding ItemsSource,RelativeSource={RelativeSource TemplatedParent}}"
  71. MaxHeight="{TemplateBinding MaxDropDownHeight}" BorderBrush="#eaeaea" >
  72. <ListBox.ItemContainerStyle>
  73. <Style TargetType="ListBoxItem">
  74. <Setter Property="Template">
  75. <Setter.Value>
  76. <ControlTemplate TargetType="{x:Type ListBoxItem}" >
  77. <Grid Height="22">
  78. <Border x:Name="bg" BorderBrush="#eaeaea" BorderThickness="0"/>
  79. <ContentPresenter x:Name="content" />
  80. <Border Background="White" Opacity="0"/>
  81. </Grid>
  82. <ControlTemplate.Triggers>
  83. <Trigger Property="IsSelected" Value="True">
  84. <Setter TargetName="bg" Property="Background" Value="#ADD6FF" />
  85. </Trigger>
  86. <MultiTrigger>
  87. <MultiTrigger.Conditions>
  88. <Condition Property="IsMouseOver" Value="true" />
  89. <Condition Property="IsSelected" Value="false"/>
  90. </MultiTrigger.Conditions>
  91. <Setter TargetName="bg" Property="Background" Value="#009BDB" />
  92. <Setter TargetName="bg" Property="Opacity" Value="0.7"/>
  93. <Setter Property="Foreground" Value="White" />
  94. </MultiTrigger>
  95. <Trigger Property="IsEnabled" Value="False">
  96. <Setter TargetName="bg" Property="Opacity" Value="0.3" />
  97. <Setter Property="Foreground" Value="Gray" />
  98. </Trigger>
  99. </ControlTemplate.Triggers>
  100. </ControlTemplate>
  101. </Setter.Value>
  102. </Setter>
  103. </Style>
  104. </ListBox.ItemContainerStyle>
  105. <ListBox.ItemTemplate>
  106. <DataTemplate>
  107. <Grid>
  108. <CheckBox x:Name="chk" Visibility="Hidden" IsChecked="{Binding IsCheck,Mode=TwoWay}" VerticalAlignment="Center"/>
  109. <CheckBox VerticalAlignment="Center" Foreground="{Binding Foreground,RelativeSource={RelativeSource AncestorType=ListBoxItem}}" IsChecked="{Binding RelativeSource={RelativeSource AncestorType=ListBoxItem},Path=IsSelected,Mode=TwoWay}" Content="{Binding Path=ViewName}" />
  110. </Grid>
  111. <DataTemplate.Triggers>
  112. <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=ListBoxItem},Path=IsSelected}" Value="true">
  113. <Setter TargetName="chk" Property="IsChecked" Value="true"/>
  114. </DataTrigger>
  115. <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType=ListBoxItem},Path=IsSelected}" Value="false">
  116. <Setter TargetName="chk" Property="IsChecked" Value="false"/>
  117. </DataTrigger>
  118. </DataTemplate.Triggers>
  119. </DataTemplate>
  120. </ListBox.ItemTemplate>
  121. </ListBox>
  122. </Grid>
  123. </Popup>
  124. </Grid>
  125.  
  126. </ControlTemplate>
  127. </Setter.Value>
  128. </Setter>
  129. </Style>

2.3、引用示例:

  1. <local:MultiComboBox x:Name="multiCmb" Margin="10" Width="200"/>

2.4、后台代码(初始化绑定数据):

  1. public partial class MainWindow : Window
  2. {
  3. public MainWindow()
  4. {
  5. InitializeComponent();
  6. MultiComboBoxList = new ObservableCollection<MultiCbxBaseData>()
  7. {
  8. new MultiCbxBaseData(){
  9. ID=,
  10. ViewName="张三",
  11. IsCheck=false
  12. },
  13. new MultiCbxBaseData(){
  14. ID=,
  15. ViewName="李四",
  16. IsCheck=false
  17. },
  18. new MultiCbxBaseData(){
  19. ID=,
  20. ViewName="王五",
  21. IsCheck=false
  22. },
  23. new MultiCbxBaseData(){
  24. ID=,
  25. ViewName="马六",
  26. IsCheck=false
  27. },
  28. new MultiCbxBaseData(){
  29. ID=,
  30. ViewName="赵七",
  31. IsCheck=false
  32. },
  33. };
  34. this.multiCmb.ItemsSource = MultiComboBoxList;
  35. }
  36.  
  37. private ObservableCollection<MultiCbxBaseData> MultiComboBoxList;
  38. }

所有代码已经上传到github:https://github.com/cmfGit/WpfDemo.git

WPF 自定义ComboBox样式的更多相关文章

  1. WPF 自定义ComboBox样式,自定义多选控件

    原文:WPF 自定义ComboBox样式,自定义多选控件 一.ComboBox基本样式 ComboBox有两种状态,可编辑和不可编辑状态.通过设置IsEditable属性可以切换控件状态. 先看基本样 ...

  2. WPF自定义Window样式(2)

    1. 引言 在上一篇中,介绍了如何建立自定义窗体.接下来,我们需要考虑将该自定义窗体基类放到类库中去,只有放到类库中,我们才能在其他地方去方便的引用该基类. 2. 创建类库 接上一篇的项目,先添加一个 ...

  3. WPF自定义Window样式(1)

    1. 引言 WPF是制作界面的一大利器.最近在做一个项目,用的就是WPF.既然使用了WPF了,那么理所当然的,需要自定义窗体样式.所使用的代码是在网上查到的,遗憾的是,整理完毕后,再找那篇帖子却怎么也 ...

  4. WPF 自定义MenuItem样式

    原文:WPF 自定义MenuItem样式 一.前言 默认的MenuItem样式比较普通,这次自定义MenuItem的样式也只是对MenuItem的颜色风格进行变化.需要其他功能的变化,大家可以根据样式 ...

  5. WPF自定义TabControl样式

    WPF自定义TabControl,TabControl美化 XAML代码: <TabControl x:Class="SunCreate.Common.Controls.TabCont ...

  6. WPF 自定义滚动条样式

    先看一下效果: 先分析一下滚动条有哪儿几部分组成: 滚动条总共有五部分组成: 两端的箭头按钮,实际类型为RepeatButton Thumb 两端的空白,实际也是RepeatButton 最后就是Th ...

  7. WPF 自定义CheckBox样式

    自定义CheckBox样式,mark一下,方便以后参考复用 设计介绍: 1.一般CheckBox模板太难看了,肯定要重写其中的模板 2.模板状态为未选中状态和选中状态,设置为默认未选中就好了. 默认状 ...

  8. WPF 自定义Calendar样式(日历样式,周六周日红色显示)

    一.WPF日历控件基本样式 通过Blend获取到Calendar需要设置的三个样式CalendarStyle.CalendarButtonStyle.CalendarDayButtonStyle.Ca ...

  9. WPF:自定义Metro样式文件夹选择对话框FolderBrowserDialog

    1.前言 WPF并没有文件选择对话框,要用也就只有使用Winform版的控件.至今我也没有寻找到一个WPF版本的文件选择对话框. 可能是我眼浊,如果各位知道有功能比较健全的WPF版文件选择对话框.文件 ...

随机推荐

  1. js改变盒子大小(上下左右)分析

    js改变盒子大小 知识点 三个mouse事件:mousedown mousemove mouseup css的定位和cursor 思路 先解决单边问题识别范围,得到所选区域 event. 根据距离,判 ...

  2. python之hasattr()、 getattr() 、setattr() 函数

    这三个方法可以实现反射和内省机制,在实际项目中很常用,功能也很强大. [转]http://www.cnblogs.com/cenyu/p/5713686.html hasattr(object, na ...

  3. java web(转)

    装载:http://www.oschina.net/question/12_52027 OSCHINA 软件库有一个分类——Web框架,该分类中包含多种编程语言的将近500个项目. Web框架是开发者 ...

  4. Numpy库(个人学习笔记)

    一样,咱的计算机还是得先拥有Python,并且安装了Numpy库.有疑问的话可以看这里呦~~~~ 下面开讲: NumPy的主要对象是齐次多维数组.它是一个元素表(通常是数字),并且都是相同类型,由正整 ...

  5. VISUALSVN: UNABLE TO CONNECT TO A REPOSITORY AT URL 无法连接主机的解决办法

    场景:我的系统是win7,安装的 VisualSVN Server 作为svn 服务器,昨天是好的,我手渐,使用鲁大师优化了系统,今天提交,更新的时候,直接提示:Unable to connect t ...

  6. Python上下文管理器

    在Python中让自己创建的函数.类.对象支持with语句,就实现了上线文管理协议.我们经常使用with open(file, "a+") as f:这样的语句,无需手动调用f.c ...

  7. 一些常用的CSS样式

    1. overflow: auto 允许盒子容器内容自动上下滚动 2. style="color:red solid" 设置元素边框样式 3.  white-space:nowra ...

  8. Redis+Restful 构造序列号和压力测试【原创】

    [本人原创],欢迎交流和分享技术,转载请附上如下内容:如果你觉得这篇文章对你有帮助,请记得帮我点赞, 谢谢!作者:kevin[转自]http://www.cnblogs.com/itshare/ 很多 ...

  9. python安装第三方库

    在编写爬虫程序时发现unsolved import 一时不解,以为是ide出问题了,其实是没有安装第三方库导致的. 于是到https://pypi.python.org/pypi/requests/去 ...

  10. new Date的兼容性问题

    标准浏览器下正常,结果ie.老版本的IOS微信公众号不支持,搞不懂,原来有兼容性问题 //beginData格式为'yyyy-mm-dd' 1 var _date = new Date(Date.pa ...