在asp.net世界中,我们的美工人员会为我们准备好静态页面,它注意包括三个部分:html、css和js。而在WPF世界里,也同样有着类似这三个部分的静态页面:Xaml、Style和Behaviors,当然,它们和前面三者的作用并不对等。Style几乎完成了css和js的功能,而Sliverlight 3中引入的Behaviors(封装到Expression Blend 3中和Expression Blend 3 SDK中)只是为了方便代码的复用,我们在后面详细来说。本文主要从Style样式和Behaviors行为两个方面来讲。

1.Style

先来看看Style类的属性:

1.1Setters

Setters是Style默认的内容属性,是Setter对象或者EventSetter对象的集合,所以可以省略Style.Setters而直接使用Setter或EventSetter。

Setter是用于设置属性值的,这个属性还得是依赖属性。EventSetter是自动关联事件处理程序的。举个例子:

xaml代码:

  1. <Window x:Class="StyleDemo.MainWindow"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. Title="MainWindow" Height="350" Width="525">
  5. <Window.Resources>
  6. <Style x:Key="labelStyle" TargetType="Label">
  7. <Setter Property="Foreground">
  8. <Setter.Value>Red</Setter.Value>
  9. </Setter>
  10. <Setter Property="Control.FontSize" Value="28" />
  11. <Setter Property="Slider.FontFamily" Value="宋体" />
  12. <EventSetter Event="MouseMove" Handler="Label_MouseMove" />
  13. </Style>
  14. <Style x:Key="buttonStyle">
  15. <Setter Property="Button.FontSize" Value="22" />
  16. <Setter Property="Button.FontFamily" Value="SimSun" />
  17. <Setter Property="Button.FontWeight" Value="Bold" />
  18. <Setter Property="Button.Background" Value="Red" />
  19. </Style>
  20. </Window.Resources>
  21. <Grid>
  22. <StackPanel>
  23. <Label Content="Hi,WPF" Style="{StaticResource labelStyle}" />
  24. <TextBlock Text="Sliverlight 5" Style="{StaticResource buttonStyle}"/>
  25. <Button Content="Click">
  26. <Button.Style>
  27. <Style>
  28. <Setter Property="Control.Background">
  29. <Setter.Value>
  30. <LinearGradientBrush>
  31. <GradientStop Offset="0" Color="Red" />
  32. <GradientStop Offset="0.5" Color="Blue" />
  33. <GradientStop Offset="1" Color="Yellow" />
  34. </LinearGradientBrush>
  35. </Setter.Value>
  36. </Setter>
  37. </Style>
  38. </Button.Style>
  39. </Button>
  40. <Button Content="DoubleClick" Style="{StaticResource buttonStyle}"/>
  41. </StackPanel>
  42. </Grid>
  43. </Window>

cs代码:

  1. private void Label_MouseMove(object sender, MouseEventArgs e)
  2. {
  3. MessageBox.Show("Mouse Move!!");
  4. }

看下效果:

需要说明一下几点:

1)以资源的形式要比内嵌的形式更具灵活性

2)在内嵌的形式中,设置属性值时,要么指定TargetType,要么使用Class.Property的形式

3)"<Setter Property="Control.Background">...</setter>"与"<Setter Property="Background">...</setter>"的区别在于,前者先去设置Control的Backgroud属性,然后应用该样式的控件继承,而后者直接去设置应用该样式的控件的属性

1.2Triggers

Triggers,即为触发器,使用它可以自动完成简单的样式改变。主要有以下几种触发器:

具个例子,一并说明下这五种触发器:

xaml代码:

  1. <Window x:Class="StyleDemo.Window1"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. xmlns:local="clr-namespace:StyleDemo"
  5. Title="Window1" Height="300" Width="300">
  6. <Window.Resources>
  7. <!--Trigger属性触发器-->
  8. <Style x:Key="triggerKey">
  9. <Style.Triggers>
  10. <Trigger Property="Control.IsMouseOver" Value="true">
  11. <Setter Property="Control.Foreground" Value="Red" />
  12. <Setter Property="Control.FontSize" Value="20" />
  13. </Trigger>
  14. </Style.Triggers>
  15. </Style>
  16. <!--MultiTrigger多条件属性触发器-->
  17. <Style x:Key="multiTriggerKey">
  18. <Style.Triggers>
  19. <MultiTrigger>
  20. <MultiTrigger.Conditions>
  21. <Condition Property="Control.Foreground" Value="Red"></Condition>
  22. <Condition Property="Control.IsMouseOver" Value="true"></Condition>
  23. </MultiTrigger.Conditions>
  24. <!--<MultiTrigger.EnterActions>
  25. <BeginStoryboard>
  26. <Storyboard>
  27. <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(FrameworkElement.Width)">
  28. <SplineDoubleKeyFrame KeyTime="00:00:00.0020000" Value="0"/>
  29. <SplineDoubleKeyFrame KeyTime="00:00:00.3450000" Value="95"/>
  30. </DoubleAnimationUsingKeyFrames>
  31. <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetProperty="(FrameworkElement.Height)">
  32. <SplineDoubleKeyFrame KeyTime="00:00:00.0020000" Value="0"/>
  33. <SplineDoubleKeyFrame KeyTime="00:00:00.3450000" Value="54"/>
  34. </DoubleAnimationUsingKeyFrames>
  35. </Storyboard>
  36. </BeginStoryboard>
  37. </MultiTrigger.EnterActions>-->
  38. <MultiTrigger.Setters>
  39. <Setter Property="Control.ToolTip" Value="Background:Red,FontSize" />
  40. </MultiTrigger.Setters>
  41. </MultiTrigger>
  42. </Style.Triggers>
  43. </Style>
  44. <!--EventTrigger事件触发器-->
  45. <Style x:Key="eventTriggerKey">
  46. <Style.Triggers>
  47. <EventTrigger RoutedEvent="Mouse.MouseEnter">
  48. <EventTrigger.Actions>
  49. <BeginStoryboard>
  50. <Storyboard>
  51. <DoubleAnimation Duration="0:0:0.2" Storyboard.TargetProperty="FontSize" To="22" />
  52. </Storyboard>
  53. </BeginStoryboard>
  54. </EventTrigger.Actions>
  55. </EventTrigger>
  56. <EventTrigger RoutedEvent="Mouse.MouseLeave">
  57. <EventTrigger.Actions>
  58. <BeginStoryboard>
  59. <Storyboard>
  60. <DoubleAnimation Duration="0:0:0.2" Storyboard.TargetProperty="FontSize" />
  61. </Storyboard>
  62. </BeginStoryboard>
  63. </EventTrigger.Actions>
  64. </EventTrigger>
  65. </Style.Triggers>
  66. </Style>
  67. <!--DataTrigger数据触发器-->
  68. <local:L2BConverter x:Key="l2bCvt" />
  69. <Style x:Key="dataTriggerKey">
  70. <Style.Triggers>
  71. <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self},Path=Text.Length,Converter={StaticResource l2bCvt}}" Value="false">
  72. <Setter Property="Control.BorderBrush" Value="Red" />
  73. <Setter Property="Control.BorderThickness" Value="1" />
  74. </DataTrigger>
  75. </Style.Triggers>
  76. </Style>
  77. <!--MultiDataTrigger多条件数据触发器-->
  78. <local:L2BConverter x:Key="l2bCvt1" />
  79. <local:S2BConverter x:Key="s2bCvt" />
  80. <Style x:Key="multiDataTriggerKey">
  81. <Style.Triggers>
  82. <MultiDataTrigger>
  83. <MultiDataTrigger.Conditions>
  84. <Condition Binding="{Binding RelativeSource={RelativeSource Self},Path=Text.Length,Converter={StaticResource l2bCvt1}}" Value="false" />
  85. <Condition Binding="{Binding RelativeSource={RelativeSource Self},Path=Text,Converter={StaticResource s2bCvt}}" Value="false" />
  86. </MultiDataTrigger.Conditions>
  87. <MultiDataTrigger.Setters>
  88. <Setter Property="Control.BorderBrush" Value="Red" />
  89. <Setter Property="Control.BorderThickness" Value="1" />
  90. </MultiDataTrigger.Setters>
  91. </MultiDataTrigger>
  92. </Style.Triggers>
  93. </Style>
  94. </Window.Resources>
  95. <Grid>
  96. <StackPanel>
  97. <Label Style="{StaticResource triggerKey}" Content="Hi,WPF" />
  98. <TextBlock Style="{StaticResource multiTriggerKey}" Foreground="Red" FontSize="16" Text="RIA World" />
  99. <Button x:Name="button" Style="{StaticResource eventTriggerKey}" Content="MouseEnter" />
  100. <TextBox Style="{StaticResource dataTriggerKey}"/>
  101. <TextBox Style="{StaticResource multiDataTriggerKey}"/>
  102. </StackPanel>
  103. </Grid>
  104. </Window>

用到的两个Converter:

字符串长度转布尔类:

  1. public class L2BConverter:IValueConverter
  2. {
  3. public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  4. {
  5. return (int)value > ? true : false;
  6. }
  7.  
  8. public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  9. {
  10. return null;
  11. }
  12. }

字符串转布尔类

  1. class S2BConverter:IValueConverter
  2. {
  3. public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  4. {
  5. Regex regex = new Regex(@"^\d*$");
  6. return !regex.IsMatch(value.ToString());
  7. }
  8.  
  9. public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  10. {
  11. throw new NotImplementedException();
  12. }
  13. }

效果大家可以copy代码运行看看。

1.3Resources

Style的Resources属性是ResourceDictionary类型,可以放一些在style中需要共享的对象资源。来看个例子:

xaml代码:

  1. <Window x:Class="StyleDemo.Window2"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. Title="Window2" Height="300" Width="300">
  5. <Window.Resources>
  6. <Style x:Key="buttonKey">
  7. <Style.Resources>
  8. <LinearGradientBrush x:Key="lgbKey">
  9. <GradientStop Offset="0" Color="Red" />
  10. <GradientStop Offset="0.5" Color="Green" />
  11. <GradientStop Offset="1" Color="Blue" />
  12. </LinearGradientBrush>
  13. </Style.Resources>
  14. <Setter Property="Control.Background" Value="{StaticResource lgbKey}" />
  15. </Style>
  16. </Window.Resources>
  17. <Grid>
  18. <StackPanel>
  19. <Button Content="button" Style="{StaticResource buttonKey}" />
  20. </StackPanel>
  21. </Grid>
  22. </Window>

效果如下:

1.4BaseOn

Style的BaseOn属性,可以实现Style的继承,从而实现多层样式。来看个简单的例子:

xaml代码:

  1. <Window x:Class="StyleDemo.Window2"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. Title="Window2" Height="300" Width="300">
  5. <Window.Resources>
  6. <Style x:Key="buttonKey">
  7. <Style.Resources>
  8. <LinearGradientBrush x:Key="lgbKey">
  9. <GradientStop Offset="0" Color="Red" />
  10. <GradientStop Offset="0.5" Color="Green" />
  11. <GradientStop Offset="1" Color="Blue" />
  12. </LinearGradientBrush>
  13. </Style.Resources>
  14. <Setter Property="Control.Background" Value="{StaticResource lgbKey}" />
  15. <Setter Property="Control.FontFamily" Value="Times New Roman" />
  16. <Setter Property="Control.FontWeight" Value="Bold" />
  17. <Setter Property="Control.FontSize" Value="18" />
  18. </Style>
  19. <Style x:Key="buttonInheritKey" BasedOn="{StaticResource buttonKey}">
  20. <Setter Property="Control.Foreground" Value="DarkOrange" />
  21. <Setter Property="Control.FontSize" Value="22" />
  22. </Style>
  23. </Window.Resources>
  24. <Grid>
  25. <StackPanel>
  26. <Button Content="button" Style="{StaticResource buttonKey}" />
  27. <Button Content="button1" Style="{StaticResource buttonInheritKey}" />
  28. </StackPanel>
  29. </Grid>
  30. </Window>

效果图如下:

1.5TargetType

这个属性,指定的是应用该Style的控件的类型。我们以一个例子为切入点来说明下:

xaml代码:

  1. <Window x:Class="StyleDemo.Window3"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. Title="Window3" Height="300" Width="300">
  5. <Window.Resources>
  6. <!--TargetType属性-->
  7. <Style TargetType="Button">
  8. <Setter Property="Foreground" Value="Yellow" />
  9. <Setter Property="FontSize" Value="28" />
  10. </Style>
  11. <Style x:Key="buttonKey">
  12. <Setter Property="Control.FontSize" Value="12" />
  13. </Style>
  14. </Window.Resources>
  15. <Grid>
  16. <StackPanel>
  17. <TextBox />
  18. <Button Content="Click" />
  19. <Button Content="Click2" Style="{StaticResource buttonKey}"/>
  20. </StackPanel>
  21. </Grid>
  22. </Window>

效果如下:

首先,你可能会奇怪,指定了TargetType的Style这里没有x:key来标识该资源,这是因为xaml解析器会自动以其对象类型来当作它的key,类似这样:x:key="{x:Type Button}"。

另外,需要说明一下几点:

1)设置了TargetType类型的Style会应用该种类型的所有控件。

2)如果某该类型控件另外还设置了Style,会进行Merge的操作(由StaticResource或DynamicResource和TargetType确定的Style和ThemeStyle的合并)。StaticResource或DynamicResource和TargetType相同的Setter属性值,前者优先级高,不同的Setter属性值均起作用。

2.Behaviors

Style提供了重用一组属性设置的方法,为帮助构建统一良好的界面迈出了重要的一步,但是,还是有很多的限制,比如对于动画的支持不够。我们知道,通常要设计一个动画效果,需要很多的xaml代码。而这样的动画也经常会在其他的地方使用,但是我们却不得不复制那一大块代码,为了DRY,微软在Expression Blend 3推出了Behaviors行为的特性。

首先,我们需要了解Behaviors这样几个关键点:

1)Behaviors可复用代码集合(UI功能),可以被任何对象附加使用

2)设计人员和开发人员只需要将它附加到元素上,而无需写任何的逻辑代码

3)一个Behaviors可以被多个对象元素同时使用

与Behaviors相关的程序集:

System.Windows.Interactivity.dll,该链接库定义了Behaviors(行为)基础类,有了该链接库支持,即可支持Behaviors(行为);

Microsoft.Expression.Interactions.dll,该链接库提供了一些扩展行为类库,以及一些Action和Trigger类,作为演示实例;

Behaviors主要包括Trigger、Action和Behavior三个部分。需要注意的是,这里的Trigger和WPF的Trigger并不完全一样,可以同时使用它们。

IAttachObject接口的定义很简单:

  1. // 摘要:
  2. // 供可以附加到另一个对象的对象使用的接口。
  3. public interface IAttachedObject
  4. {
  5. // 摘要:
  6. // 获得关联的对象。
  7. //
  8. // 备注:
  9. // 代表此实例附加到的对象。
  10. DependencyObject AssociatedObject { get; }
  11.  
  12. // 摘要:
  13. // 附加到指定的对象。
  14. //
  15. // 参数:
  16. // dependencyObject:
  17. // 要附加到的对象。
  18. void Attach(DependencyObject dependencyObject);
  19. //
  20. // 摘要:
  21. // 将此实例与其关联的对象分离。
  22. void Detach();
  23. }

AssociatedObject是一个只读的依赖对象属性,它指定行为的应用者。

2.1自定义一个Behavior

下面我们来自己定义一个Behaviors看看,要实现的效果是在Canvas中的控件可任意拖动:

先定义一个继承自Behavior<UIElement>的DragInCanvasBehavior类

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Interactivity;
  9. using System.Windows.Media;
  10.  
  11. namespace CustomBehaviorsLib
  12. {
  13. public class DragInCanvasBehavior:Behavior<UIElement>
  14. {
  15. protected override void OnAttached()
  16. {
  17. base.OnAttached();
  18. //Hook up event handlers
  19. this.AssociatedObject.MouseLeftButtonDown += AssociatedObject_MouseLeftButtonDown;
  20. this.AssociatedObject.MouseMove += AssociatedObject_MouseMove;
  21. this.AssociatedObject.MouseLeftButtonUp += AssociatedObject_MouseLeftButtonUp;
  22. }
  23.  
  24. void AssociatedObject_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
  25. {
  26. if (isDragging)
  27. {
  28. AssociatedObject.ReleaseMouseCapture();
  29. isDragging = false;
  30. }
  31. }
  32.  
  33. void AssociatedObject_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
  34. {
  35. if (isDragging)
  36. {
  37. Point point = e.GetPosition(canvas);
  38. AssociatedObject.SetValue(Canvas.TopProperty, point.Y-mouseOffset.Y);
  39. AssociatedObject.SetValue(Canvas.LeftProperty, point.X - mouseOffset.X);
  40. }
  41. }
  42. private Canvas canvas;
  43. private bool isDragging = false;
  44. private Point mouseOffset;
  45. void AssociatedObject_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
  46. {
  47. if (canvas == null)
  48. canvas = (Canvas)VisualTreeHelper.GetParent(this.AssociatedObject);
  49. isDragging = true;
  50. mouseOffset = e.GetPosition(AssociatedObject);
  51. AssociatedObject.CaptureMouse();
  52. }
  53. protected override void OnDetaching()
  54. {
  55. base.OnDetaching();
  56. //detach event handlers
  57. this.AssociatedObject.MouseLeftButtonDown += AssociatedObject_MouseLeftButtonDown;
  58. this.AssociatedObject.MouseMove += AssociatedObject_MouseMove;
  59. this.AssociatedObject.MouseLeftButtonUp += AssociatedObject_MouseLeftButtonUp;
  60. }
  61. }
  62. }

然后在window4.xaml中添加对DragInCanvasBehavior类所在类库的引用,同时添加System.Window.Interactivity.dll的引用。

xaml代码如下:

  1. <Window x:Class="StyleDemo.Window4"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
  5. xmlns:custom="clr-namespace:CustomBehaviorsLib;assembly=CustomBehaviorsLib"
  6. Title="Window4" Height="300" Width="300">
  7. <Grid>
  8. <Canvas x:Name="p_canvas">
  9. <Canvas x:Name="c_canvas1" Width="100" Height="100" Background="Yellow" />
  10. <Canvas x:Name="c_canvas2" Width="100" Height="100" Canvas.Left="110" Background="Red">
  11. <i:Interaction.Behaviors>
  12. <custom:DragInCanvasBehavior />
  13. </i:Interaction.Behaviors>
  14. </Canvas>
  15. <Canvas x:Name="c_canvas3" Width="100" Height="100" Canvas.Top="110" Background="Blue" />
  16. </Canvas>
  17. </Grid>
  18. </Window>

通过向BehaviorCollection类型的Interaction.Behaviors附加属性添加DragInCanvasBehavior实例。

效果如下:

这里只是给红色的Canvas添加了DragInCanvasBehavior,所以只有红色的Canvas可以Drag。

Expression Blend 3 以及之后的版本(4和4.5)都有Behaviors提供了很好的支持,内部提供了好多封装好的Behaviors。况且,使用blend可以很方便简单的使用它。

2.2Expression Blend中Behaviors

Expression Blend是和Visual Studio配套使用的,也就是说对应的采用的是相同的解决方案文件格式,Blend 3对应VS2008,Blend 4对应VS2010,Blend 5对应VS2012。

这里提供许多现成的行为,也包含自定义的Behaviors。用法基本类似,这里我们以MouseDragElementBehavior为例,来介绍下在Expression Blend中对Behaviors的使用。

先向界面拖放一个主Canvas,里面放三个子Canvas,背景颜色分别设为Yello、Red和Blue。然后将MouseDragElementBehavior拖放到红色的子Canvas上面,代码便自动完成了,实现了与上面相同的效果,及其方便快捷。

有关Expression Blend的使用技巧,将会单独来讲,在后面模板和动画的学习中还将会提到。

WPF学习(9)样式和行为的更多相关文章

  1. WPF自定义控件与样式(3)-TextBox & RichTextBox & PasswordBox样式、水印、Label标签、功能扩展

    一.前言.预览 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等,若有不明白的地方可以参考本系列前面的文章,文末附有部分文章链接. 本文主要是对文本 ...

  2. WPF自定义控件与样式(1)-矢量字体图标(iconfont)

    一.图标字体 图标字体在网页开发上运用非常广泛,具体可以网络搜索了解,网页上的运用有很多例子,如Bootstrap.但在C/S程序中使用还不多,字体图标其实就是把矢量图形打包到字体文件里,就像使用一般 ...

  3. WPF自定义控件与样式(2)-自定义按钮FButton

    一.前言.效果图 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等,若有不明白的地方可以参考本系列前面的文章,文末附有部分文章链接. 还是先看看效果 ...

  4. WPF自定义控件与样式(15)-终结篇 & 系列文章索引 & 源码共享

    系列文章目录  WPF自定义控件与样式(1)-矢量字体图标(iconfont) WPF自定义控件与样式(2)-自定义按钮FButton WPF自定义控件与样式(3)-TextBox & Ric ...

  5. WPF自定义控件与样式(4)-CheckBox/RadioButton自定义样式

    一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等,若有不明白的地方可以参考本系列前面的文章,文末附有部分文章链接. 本文主要内容: Che ...

  6. WPF自定义控件与样式(5)-Calendar/DatePicker日期控件自定义样式及扩展

    一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等,若有不明白的地方可以参考本系列前面的文章,文末附有部分文章链接. 本文主要内容: 日历控 ...

  7. WPF自定义控件与样式(6)-ScrollViewer与ListBox自定义样式

    一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等,若有不明白的地方可以参考本系列前面的文章,文末附有部分文章链接. 本文主要内容: Scr ...

  8. WPF自定义控件与样式(7)-列表控件DataGrid与ListView自定义样式

    一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等,若有不明白的地方可以参考本系列前面的文章,文末附有部分文章链接. 本文主要内容: Dat ...

  9. WPF自定义控件与样式(8)-ComboBox与自定义多选控件MultComboBox

    一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等,若有不明白的地方可以参考本系列前面的文章,文末附有部分文章链接. 本文主要内容: 下拉选 ...

  10. WPF自定义控件与样式(9)-树控件TreeView与菜单Menu-ContextMenu

    一.前言 申明:WPF自定义控件与样式是一个系列文章,前后是有些关联的,但大多是按照由简到繁的顺序逐步发布的等,若有不明白的地方可以参考本系列前面的文章,文末附有部分文章链接. 本文主要内容: 菜单M ...

随机推荐

  1. webservice一片:其中在外线呼叫数据,查看返回数据

    经Android数据被访问,返回的数据(json格公式,object数据类型:strJson) 业务需求:经webservice调用外部暴露数据并返回json数据序列化.阅读到数据库表:[SQ_Eve ...

  2. 1104. Don’t Ask Woman about Her Age(数论)

    a*b^n(mod(b-1) =a(mod(b-1) http://acm.timus.ru/problem.aspx?space=1&num=1104 #include <stdio. ...

  3. Windows Phone开发(25):启动器与选择器之WebBrowserTask

    原文:Windows Phone开发(25):启动器与选择器之WebBrowserTask 从名字上就看出来,这个家伙就是打开浏览并浏览到指定页面. 它有两个用途完全一样的属性:Uri属性是Syste ...

  4. 【原创】leetCodeOj --- Candy 解题报告

    题目地址: https://leetcode.com/problems/candy/ 题目内容: Candy Total Accepted: 43150 Total Submissions: 2038 ...

  5. 基本调试命令 - u/ub/uf

    原:http://www.cnblogs.com/developersupport/p/windbgcommand-u.html 在调试过程中难免会遇到须要反编译代码来分析逻辑的时候.在windbg中 ...

  6. 【原创】leetCodeOj ---Partition List 解题报告

    原题地址: https://oj.leetcode.com/problems/partition-list/ 题目内容: Given a linked list and a value x, part ...

  7. MVC 检测用户是否登录

         当我们访问一个网站的需求检測用户是否已经登录(通过Session是否为null),我们知道在WebForm中能够定义一个BasePage类让他继承System.Web.UI.Page,重写它 ...

  8. Android_使用StrictMode 调试开发

    本博文为子墨原创,转载请注明出处! http://blog.csdn.net/zimo2013/article/details/40076049 1.StrictMode简单介绍 自Android 2 ...

  9. C++学习笔记9-运算符重载

    1. 重载运营商必须有一个类类型的操作数 对于内置类型运营商.它的意义不能改变. 例如,内置整数加法运算不能被重新定义: // error: cannotredefine built-in opera ...

  10. hdu2377Bus Pass(构建更复杂的图+spfa)

    主题链接: 啊哈哈,点我点我 思路: 题目是给了非常多个车站.然后要你找到一个社区距离这些车站的最大值最小..所以对每一个车站做一次spfa.那么就得到了到每一个社区的最大值,最后对每一个社区扫描一次 ...