偶然的机会想做一个双手臂运转的机械手动作动画,重要的是有前辈写好的可以模仿:WPF开发经验-实现一种三轴机械手控件 - 一团静火 - 博客园
shit,公司禁止上传图片了
-------------------------------------------------------------------------------------
涵盖知识:
1.不可不知的WPF转换(Transform)_wpf matrixtransform-CSDN博客;
2.WPF中的VisualState(视觉状态)_wpf visualstate-CSDN博客;
3.WPF中RenderTransform详解_rendertransformorigin-CSDN博客
----------------------------------------------------------------------------------------
把代码放上来
1.自定义的机械手控件
public class WaferRobotControl: Control{static WaferRobotControl(){DefaultStyleKeyProperty.OverrideMetadata(typeof(WaferRobotControl), new FrameworkPropertyMetadata(typeof(WaferRobotControl)));}public static readonly DependencyProperty WaferProperty = DependencyProperty.Register("Wafer", typeof(int), typeof(WaferRobotControl));public int Wafer { get => (int)GetValue(WaferProperty); set => SetValue(WaferProperty, value); }public static readonly DependencyProperty RobotWActionProperty = DependencyProperty.Register("RobotWAction",typeof(WaferRobotWAction),typeof(WaferRobotControl),new PropertyMetadata(WaferRobotWAction.W_Origin, RobotWActionPropertyChangedCallback));public WaferRobotWAction RobotWAction{get => (WaferRobotWAction)GetValue(RobotWActionProperty);set => SetValue(RobotWActionProperty, value);}private static void RobotWActionPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e){var control = d as WaferRobotControl;var oldAct = (WaferRobotWAction)e.OldValue;var newAct = (WaferRobotWAction)e.NewValue;switch (newAct){case WaferRobotWAction.W_Origin:VisualStateManager.GoToState(control, newAct.ToString(), true);break;case WaferRobotWAction.W_StickOut:if (newAct != oldAct){VisualStateManager.GoToState(control, newAct.ToString(), true);}break;default:break;}}public static readonly DependencyProperty RobotRActionProperty = DependencyProperty.Register("RobotRAction",typeof(WaferRobotRAction),typeof(WaferRobotControl),new PropertyMetadata(WaferRobotRAction.R_Origin, RobotRActionPropertyChangedCallback));public WaferRobotRAction RobotRAction{get => (WaferRobotRAction)GetValue(RobotRActionProperty);set => SetValue(RobotRActionProperty, value);}private static void RobotRActionPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e){var control = d as WaferRobotControl;var oldAct = (WaferRobotRAction)e.OldValue;var newAct = (WaferRobotRAction)e.NewValue;switch (newAct){case WaferRobotRAction.R_Origin:VisualStateManager.GoToState(control, newAct.ToString(), true);break;case WaferRobotRAction.R_StickOut:if (newAct != oldAct){VisualStateManager.GoToState(control, newAct.ToString(), true);}break;default:break;}}public static readonly DependencyProperty RobotTActionProperty = DependencyProperty.Register("RobotTAction",typeof(WaferRobotTAction),typeof(WaferRobotControl),new PropertyMetadata(WaferRobotTAction.T_Origin, RobotTActionPropertyChangedCallback));public WaferRobotTAction RobotTAction{get => (WaferRobotTAction)GetValue(RobotTActionProperty);set => SetValue(RobotTActionProperty, value);}private static void RobotTActionPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e){var control = d as WaferRobotControl;var oldAct = (WaferRobotTAction)e.OldValue;var newAct = (WaferRobotTAction)e.NewValue;switch (newAct){case WaferRobotTAction.T_Origin:VisualStateManager.GoToState(control, newAct.ToString(), true);break;case WaferRobotTAction.T_CW:if (newAct != oldAct){VisualStateManager.GoToState(control, newAct.ToString(), true);}break;case WaferRobotTAction.T_CCW:if (newAct != oldAct){VisualStateManager.GoToState(control, newAct.ToString(), true);}break;default:break;}}public override void OnApplyTemplate(){base.OnApplyTemplate();VisualStateManager.GoToState(this, WaferRobotWAction.W_Origin.ToString(), true);VisualStateManager.GoToState(this, WaferRobotRAction.R_Origin.ToString(), true);VisualStateManager.GoToState(this, WaferRobotTAction.T_Origin.ToString(), true);}}
}
2.机械手手臂(轴)状态
public enum WaferRobotRAction
{R_Origin,R_StickOut
}
public enum WaferRobotWAction
{W_Origin,W_StickOut
}
public enum WaferRobotTAction
{T_Origin,T_CW,T_CCW
}
3.控件对应的模版
<SolidColorBrush x:Key="robotBorderBrush" Color="#030303" />
<Style TargetType="{x:Type myWaferRobot:WaferRobotControl}" ><Setter Property="Cursor" Value="Hand" /><Setter Property="Width" Value="200"/><Setter Property="Height" Value="300"/><Setter Property="Template"><Setter.Value><ControlTemplate TargetType="{x:Type myWaferRobot:WaferRobotControl}"><Viewbox x:Name="viewbox" Stretch="Fill"><VisualStateManager.VisualStateGroups><!--<VisualStateGroup Name="RobotActions"><VisualStateGroup.Transitions><VisualTransition To="Z_CW"><Storyboard FillBehavior="HoldEnd"><DoubleAnimationUsingKeyFrames Storyboard.TargetName="robotZAct" Storyboard.TargetProperty="Y"><LinearDoubleKeyFrame Value="-90" KeyTime="0:0:1"/></DoubleAnimationUsingKeyFrames><DoubleAnimationUsingKeyFrames Storyboard.TargetName="robotUpDownAct" Storyboard.TargetProperty="Y"><LinearDoubleKeyFrame Value="-90" KeyTime="0:0:1"/></DoubleAnimationUsingKeyFrames></Storyboard></VisualTransition><VisualTransition To="Z_CCW"><Storyboard FillBehavior="HoldEnd"><DoubleAnimationUsingKeyFrames Storyboard.TargetName="robotZAct" Storyboard.TargetProperty="Y"><LinearDoubleKeyFrame Value="0" KeyTime="0:0:1"/></DoubleAnimationUsingKeyFrames><DoubleAnimationUsingKeyFrames Storyboard.TargetName="robotUpDownAct" Storyboard.TargetProperty="Y"><LinearDoubleKeyFrame Value="0" KeyTime="0:0:1"/></DoubleAnimationUsingKeyFrames></Storyboard></VisualTransition></VisualStateGroup.Transitions><VisualState Name="Z_Origin"><Storyboard FillBehavior="HoldEnd"><DoubleAnimationUsingKeyFrames Storyboard.TargetName="robotZAct" Storyboard.TargetProperty="Y" ><LinearDoubleKeyFrame Value="0" KeyTime="0:0:0"/></DoubleAnimationUsingKeyFrames><DoubleAnimationUsingKeyFrames Storyboard.TargetName="robotUpDownAct" Storyboard.TargetProperty="Y" ><LinearDoubleKeyFrame Value="0" KeyTime="0:0:0"/></DoubleAnimationUsingKeyFrames></Storyboard></VisualState><VisualState Name="Z_CW"><Storyboard FillBehavior="HoldEnd"><DoubleAnimationUsingKeyFrames Storyboard.TargetName="robotZAct" Storyboard.TargetProperty="Y" Duration="0" ><LinearDoubleKeyFrame Value="-90" KeyTime="0:0:0"/></DoubleAnimationUsingKeyFrames><DoubleAnimationUsingKeyFrames Storyboard.TargetName="robotUpDownAct" Storyboard.TargetProperty="Y" ><LinearDoubleKeyFrame Value="-90" KeyTime="0:0:0"/></DoubleAnimationUsingKeyFrames></Storyboard></VisualState><VisualState Name="Z_CCW"><Storyboard FillBehavior="HoldEnd"><DoubleAnimationUsingKeyFrames Storyboard.TargetName="robotZAct" Storyboard.TargetProperty="Y" ><LinearDoubleKeyFrame Value="0" KeyTime="0:0:0"/></DoubleAnimationUsingKeyFrames><DoubleAnimationUsingKeyFrames Storyboard.TargetName="robotUpDownAct" Storyboard.TargetProperty="Y" ><LinearDoubleKeyFrame Value="0" KeyTime="0:0:0"/></DoubleAnimationUsingKeyFrames></Storyboard></VisualState></VisualStateGroup>--><VisualStateGroup Name="RobotArmRActions"><VisualStateGroup.Transitions><VisualTransition To="R_StickOut"><Storyboard FillBehavior="HoldEnd" SpeedRatio="6"><DoubleAnimationUsingKeyFrames Storyboard.TargetName="armRT1RotateAct" Storyboard.TargetProperty="Angle"><LinearDoubleKeyFrame Value="70" KeyTime="0:0:0"/><LinearDoubleKeyFrame Value="0" KeyTime="0:0:9"/></DoubleAnimationUsingKeyFrames><DoubleAnimationUsingKeyFrames Storyboard.TargetName="armRT2ArmRotateAct" Storyboard.TargetProperty="Angle"><LinearDoubleKeyFrame Value="-65" KeyTime="0:0:0"/><LinearDoubleKeyFrame Value="0" KeyTime="0:0:9"/></DoubleAnimationUsingKeyFrames><DoubleAnimationUsingKeyFrames Storyboard.TargetName="armRT2Act" Storyboard.TargetProperty="X"><LinearDoubleKeyFrame Value="90" KeyTime="0:0:0"/><LinearDoubleKeyFrame Value="80" KeyTime="0:0:1"/><LinearDoubleKeyFrame Value="70" KeyTime="0:0:2"/><LinearDoubleKeyFrame Value="60" KeyTime="0:0:3"/><LinearDoubleKeyFrame Value="50" KeyTime="0:0:4"/><LinearDoubleKeyFrame Value="40" KeyTime="0:0:5"/><LinearDoubleKeyFrame Value="30" KeyTime="0:0:6"/><LinearDoubleKeyFrame Value="20" KeyTime="0:0:7"/><LinearDoubleKeyFrame Value="10" KeyTime="0:0:8"/><LinearDoubleKeyFrame Value="0 " KeyTime="0:0:9"/></DoubleAnimationUsingKeyFrames></Storyboard></VisualTransition><VisualTransition To="R_Origin"><Storyboard FillBehavior="HoldEnd" SpeedRatio="6"><DoubleAnimationUsingKeyFrames Storyboard.TargetName="armRT1RotateAct" Storyboard.TargetProperty="Angle"><LinearDoubleKeyFrame Value="0" KeyTime="0:0:0"/><LinearDoubleKeyFrame Value="68" KeyTime="0:0:9"/></DoubleAnimationUsingKeyFrames><DoubleAnimationUsingKeyFrames Storyboard.TargetName="armRT2ArmRotateAct" Storyboard.TargetProperty="Angle"><LinearDoubleKeyFrame Value="0" KeyTime="0:0:0"/><LinearDoubleKeyFrame Value="-65" KeyTime="0:0:9"/></DoubleAnimationUsingKeyFrames><DoubleAnimationUsingKeyFrames Storyboard.TargetName="armRT2Act" Storyboard.TargetProperty="X"><LinearDoubleKeyFrame Value="90" KeyTime="0:0:9"/><LinearDoubleKeyFrame Value="80" KeyTime="0:0:8"/><LinearDoubleKeyFrame Value="70" KeyTime="0:0:7"/><LinearDoubleKeyFrame Value="60" KeyTime="0:0:6"/><LinearDoubleKeyFrame Value="50" KeyTime="0:0:5"/><LinearDoubleKeyFrame Value="40" KeyTime="0:0:4"/><LinearDoubleKeyFrame Value="30" KeyTime="0:0:3"/><LinearDoubleKeyFrame Value="20" KeyTime="0:0:2"/><LinearDoubleKeyFrame Value="10" KeyTime="0:0:1"/><LinearDoubleKeyFrame Value="0 " KeyTime="0:0:0"/></DoubleAnimationUsingKeyFrames></Storyboard></VisualTransition></VisualStateGroup.Transitions><VisualState Name="R_StickOut"><Storyboard FillBehavior="HoldEnd"><DoubleAnimationUsingKeyFrames Storyboard.TargetName="armRT1RotateAct" Storyboard.TargetProperty="Angle"><LinearDoubleKeyFrame Value="0" KeyTime="0:0:0"/></DoubleAnimationUsingKeyFrames><DoubleAnimationUsingKeyFrames Storyboard.TargetName="armRT2ArmRotateAct" Storyboard.TargetProperty="Angle"><LinearDoubleKeyFrame Value="0" KeyTime="0:0:0"/></DoubleAnimationUsingKeyFrames><DoubleAnimationUsingKeyFrames Storyboard.TargetName="armRT2Act" Storyboard.TargetProperty="X"><LinearDoubleKeyFrame Value="0" KeyTime="0:0:0"/></DoubleAnimationUsingKeyFrames></Storyboard></VisualState><VisualState Name="R_Origin"><Storyboard FillBehavior="HoldEnd"><DoubleAnimationUsingKeyFrames Storyboard.TargetName="armRT1RotateAct" Storyboard.TargetProperty="Angle"><LinearDoubleKeyFrame Value="68" KeyTime="0:0:0"/></DoubleAnimationUsingKeyFrames><DoubleAnimationUsingKeyFrames Storyboard.TargetName="armRT2ArmRotateAct" Storyboard.TargetProperty="Angle"><LinearDoubleKeyFrame Value="-65" KeyTime="0:0:0"/></DoubleAnimationUsingKeyFrames><DoubleAnimationUsingKeyFrames Storyboard.TargetName="armRT2Act" Storyboard.TargetProperty="X"><LinearDoubleKeyFrame Value="90" KeyTime="0:0:0"/></DoubleAnimationUsingKeyFrames></Storyboard></VisualState></VisualStateGroup><VisualStateGroup Name="RobotArmWActions"><VisualStateGroup.Transitions><VisualTransition To="W_StickOut"><Storyboard FillBehavior="HoldEnd" SpeedRatio="6"><DoubleAnimationUsingKeyFrames Storyboard.TargetName="armWT1RotateAct" Storyboard.TargetProperty="Angle"><LinearDoubleKeyFrame Value="-68" KeyTime="0:0:0"/><LinearDoubleKeyFrame Value="0" KeyTime="0:0:9"/></DoubleAnimationUsingKeyFrames><DoubleAnimationUsingKeyFrames Storyboard.TargetName="armWT2ArmRotateAct" Storyboard.TargetProperty="Angle"><LinearDoubleKeyFrame Value="63" KeyTime="0:0:0"/><LinearDoubleKeyFrame Value="0" KeyTime="0:0:9"/></DoubleAnimationUsingKeyFrames><DoubleAnimationUsingKeyFrames Storyboard.TargetName="armWT2Act" Storyboard.TargetProperty="X"><LinearDoubleKeyFrame Value="90" KeyTime="0:0:0"/><LinearDoubleKeyFrame Value="80" KeyTime="0:0:1"/><LinearDoubleKeyFrame Value="70" KeyTime="0:0:2"/><LinearDoubleKeyFrame Value="60" KeyTime="0:0:3"/><LinearDoubleKeyFrame Value="50" KeyTime="0:0:4"/><LinearDoubleKeyFrame Value="40" KeyTime="0:0:5"/><LinearDoubleKeyFrame Value="30" KeyTime="0:0:6"/><LinearDoubleKeyFrame Value="20" KeyTime="0:0:7"/><LinearDoubleKeyFrame Value="10" KeyTime="0:0:8"/><LinearDoubleKeyFrame Value="0 " KeyTime="0:0:9"/></DoubleAnimationUsingKeyFrames></Storyboard></VisualTransition><VisualTransition To="W_Origin"><Storyboard FillBehavior="HoldEnd" SpeedRatio="6"><DoubleAnimationUsingKeyFrames Storyboard.TargetName="armWT1RotateAct" Storyboard.TargetProperty="Angle"><LinearDoubleKeyFrame Value="0" KeyTime="0:0:0"/><LinearDoubleKeyFrame Value="-68" KeyTime="0:0:9"/></DoubleAnimationUsingKeyFrames><DoubleAnimationUsingKeyFrames Storyboard.TargetName="armWT2ArmRotateAct" Storyboard.TargetProperty="Angle"><LinearDoubleKeyFrame Value="0" KeyTime="0:0:0"/><LinearDoubleKeyFrame Value="63" KeyTime="0:0:9"/></DoubleAnimationUsingKeyFrames><DoubleAnimationUsingKeyFrames Storyboard.TargetName="armWT2Act" Storyboard.TargetProperty="X"><LinearDoubleKeyFrame Value="90" KeyTime="0:0:9"/><LinearDoubleKeyFrame Value="80" KeyTime="0:0:8"/><LinearDoubleKeyFrame Value="70" KeyTime="0:0:7"/><LinearDoubleKeyFrame Value="60" KeyTime="0:0:6"/><LinearDoubleKeyFrame Value="50" KeyTime="0:0:5"/><LinearDoubleKeyFrame Value="40" KeyTime="0:0:4"/><LinearDoubleKeyFrame Value="30" KeyTime="0:0:3"/><LinearDoubleKeyFrame Value="20" KeyTime="0:0:2"/><LinearDoubleKeyFrame Value="10" KeyTime="0:0:1"/><LinearDoubleKeyFrame Value="0 " KeyTime="0:0:0"/></DoubleAnimationUsingKeyFrames></Storyboard></VisualTransition></VisualStateGroup.Transitions><VisualState Name="W_StickOut"><Storyboard FillBehavior="HoldEnd"><DoubleAnimationUsingKeyFrames Storyboard.TargetName="armWT1RotateAct" Storyboard.TargetProperty="Angle"><LinearDoubleKeyFrame Value="0" KeyTime="0:0:0"/></DoubleAnimationUsingKeyFrames><DoubleAnimationUsingKeyFrames Storyboard.TargetName="armWT2ArmRotateAct" Storyboard.TargetProperty="Angle"><LinearDoubleKeyFrame Value="0" KeyTime="0:0:0"/></DoubleAnimationUsingKeyFrames><DoubleAnimationUsingKeyFrames Storyboard.TargetName="armWT2Act" Storyboard.TargetProperty="X"><LinearDoubleKeyFrame Value="0" KeyTime="0:0:0"/></DoubleAnimationUsingKeyFrames></Storyboard></VisualState><VisualState Name="W_Origin"><Storyboard FillBehavior="HoldEnd"><DoubleAnimationUsingKeyFrames Storyboard.TargetName="armWT1RotateAct" Storyboard.TargetProperty="Angle"><LinearDoubleKeyFrame Value="-68" KeyTime="0:0:0"/></DoubleAnimationUsingKeyFrames><DoubleAnimationUsingKeyFrames Storyboard.TargetName="armWT2ArmRotateAct" Storyboard.TargetProperty="Angle"><LinearDoubleKeyFrame Value="63" KeyTime="0:0:0"/></DoubleAnimationUsingKeyFrames><DoubleAnimationUsingKeyFrames Storyboard.TargetName="armWT2Act" Storyboard.TargetProperty="X"><LinearDoubleKeyFrame Value="90" KeyTime="0:0:0"/></DoubleAnimationUsingKeyFrames></Storyboard></VisualState></VisualStateGroup><VisualStateGroup Name="RobotTActions"><VisualStateGroup.Transitions><VisualTransition To="T_Origin"><Storyboard FillBehavior="HoldEnd"><DoubleAnimationUsingKeyFrames Storyboard.TargetName="robotRotateAct" Storyboard.TargetProperty="Angle"><LinearDoubleKeyFrame Value="90" KeyTime="0:0:1"/></DoubleAnimationUsingKeyFrames></Storyboard></VisualTransition><VisualTransition To="T_CW"><Storyboard FillBehavior="HoldEnd"><DoubleAnimationUsingKeyFrames Storyboard.TargetName="robotRotateAct" Storyboard.TargetProperty="Angle"><LinearDoubleKeyFrame Value="180" KeyTime="0:0:1"/></DoubleAnimationUsingKeyFrames></Storyboard></VisualTransition><VisualTransition To="T_CCW"><Storyboard FillBehavior="HoldEnd"><DoubleAnimationUsingKeyFrames Storyboard.TargetName="robotRotateAct" Storyboard.TargetProperty="Angle"><LinearDoubleKeyFrame Value="0" KeyTime="0:0:1"/></DoubleAnimationUsingKeyFrames></Storyboard></VisualTransition></VisualStateGroup.Transitions><VisualState Name="T_Origin"><Storyboard FillBehavior="HoldEnd"><DoubleAnimationUsingKeyFrames Storyboard.TargetName="robotRotateAct" Storyboard.TargetProperty="Angle"><LinearDoubleKeyFrame Value="90" KeyTime="0:0:0"/></DoubleAnimationUsingKeyFrames></Storyboard></VisualState><VisualState Name="T_CCW"><Storyboard FillBehavior="HoldEnd"><DoubleAnimationUsingKeyFrames Storyboard.TargetName="robotRotateAct" Storyboard.TargetProperty="Angle"><LinearDoubleKeyFrame Value="00" KeyTime="0:0:0"/></DoubleAnimationUsingKeyFrames></Storyboard></VisualState><VisualState Name="T_CW"><Storyboard FillBehavior="HoldEnd"><DoubleAnimationUsingKeyFrames Storyboard.TargetName="robotRotateAct" Storyboard.TargetProperty="Angle"><LinearDoubleKeyFrame Value="180" KeyTime="0:0:0"/></DoubleAnimationUsingKeyFrames></Storyboard></VisualState></VisualStateGroup></VisualStateManager.VisualStateGroups><Canvas Width="200" Height="300" Background="Transparent" ><Canvas x:Name="robot" Width="200" Height="200" RenderTransformOrigin="0.5 0.5" Background="BlanchedAlmond" ><Canvas.RenderTransform><TransformGroup><RotateTransform x:Name="robotRotateAct"/><TranslateTransform x:Name="robotUpDownAct"/></TransformGroup></Canvas.RenderTransform><Canvas x:Name="armWT1" Width="200" Height="100" Canvas.Left="0" Canvas.Top="50" RenderTransformOrigin="0.5 0.5" Background="Transparent"><Canvas.RenderTransform><RotateTransform x:Name="armWT1RotateAct"/></Canvas.RenderTransform><Canvas x:Name="armWT1Arm" Width="70" Height="30" Canvas.Left="30" Canvas.Top="35" ><Path Stroke="{StaticResource robotBorderBrush}" Fill="#FF7F50" StrokeThickness="1" StrokeEndLineCap="Round" ><Path.Data><PathGeometry><PathFigure StartPoint="0 5" IsClosed="True"><LineSegment Point="51 0"/><LineSegment Point="51 30" IsStroked="False"/><LineSegment Point="0 25"/><LineSegment Point="0 5" IsStroked="False"/></PathFigure></PathGeometry></Path.Data></Path><Path Stroke="{StaticResource robotBorderBrush}" StrokeThickness="1" Canvas.Left="0" StrokeEndLineCap="Round" StrokeStartLineCap="Round" Fill="#FF7F50"Data="M 0,5 A 10,10 0 0 0 0,25"></Path></Canvas><Canvas x:Name="armWT1Center" Width="40" Height="40" Canvas.Left="80" Canvas.Top="30" ><Path Stroke="{StaticResource robotBorderBrush}" Fill="Blue" StrokeThickness="1" StrokeEndLineCap="Round" ><Path.Data><PathGeometry><PathFigure StartPoint="0 6" IsClosed="True"><LineSegment Point="6 0"/><LineSegment Point="34 0"/><LineSegment Point="40 6"/><LineSegment Point="40 34"/><LineSegment Point="34 40"/><LineSegment Point="6 40"/><LineSegment Point="0 34"/></PathFigure></PathGeometry></Path.Data></Path></Canvas></Canvas><Canvas x:Name="armWT2" Width="70" Height="50" Canvas.Left="-95" Canvas.Top="80" Background="Transparent"><Canvas.RenderTransform><TransformGroup><TranslateTransform x:Name="armWT2Act"></TranslateTransform></TransformGroup></Canvas.RenderTransform><Canvas x:Name="armWT2Arm" Width="70" Height="20" Canvas.Left="50" Canvas.Top="10" RenderTransformOrigin="0 0.5" ><Canvas.RenderTransform><RotateTransform x:Name="armWT2ArmRotateAct"/></Canvas.RenderTransform><Path Stroke="{StaticResource robotBorderBrush}" StrokeThickness="1" Canvas.Left="70" StrokeEndLineCap="Round" StrokeStartLineCap="Round" Fill="#6495ED"Data="M 0,0 A 10,10 0 0 1 0,20"></Path><Path Stroke="{StaticResource robotBorderBrush}" StrokeThickness="1" Canvas.Left="0" StrokeEndLineCap="Round" StrokeStartLineCap="Round" Fill="#6495ED"Data="M 0,0 A 10,10 0 0 0 0,20"></Path><Path Stroke="{StaticResource robotBorderBrush}" Fill="#6495ED" StrokeThickness="1" StrokeEndLineCap="Round" ><Path.Data><PathGeometry><PathFigure StartPoint="70 0" ><LineSegment Point="0 0" /><LineSegment Point="0 20" IsStroked="False"/><LineSegment Point="70 20"/><LineSegment Point="70 0" IsStroked="False"/></PathFigure></PathGeometry></Path.Data></Path><Ellipse Width="12" Height="12" Stroke="#030303" StrokeThickness="2" Fill="Transparent" Canvas.Top="4" Canvas.Left="62"/></Canvas><Canvas x:Name="armWGripper" Height="40" Width="50" Canvas.Left="0" Canvas.Top="0" ><Path Stroke="{StaticResource robotBorderBrush}" StrokeThickness="2" StrokeEndLineCap="Round" ><Path.Data><PathGeometry><PathFigure StartPoint="30 14" ><LineSegment Point="10 14" /><LineSegment Point="4 8" /><LineSegment Point="-6 8" /></PathFigure><PathFigure StartPoint="30 26" ><LineSegment Point="10 26" /><LineSegment Point="4 32" /><LineSegment Point="-6 32" /></PathFigure></PathGeometry></Path.Data></Path><Path Stroke="{StaticResource robotBorderBrush}" Fill="#7A7E90" StrokeThickness="1" StrokeEndLineCap="Round" ><Path.Data><PathGeometry><PathFigure StartPoint="40 0" ><LineSegment Point="60 0" /><LineSegment Point="60 40" /><LineSegment Point="40 40" /><LineSegment Point="30 30" /><LineSegment Point="30 10" /><LineSegment Point="40 0" /></PathFigure></PathGeometry></Path.Data></Path><Path Stroke="{StaticResource robotBorderBrush}" Fill="#7A7E90" StrokeThickness="1" StrokeEndLineCap="Round" ><Path.Data><PathGeometry><PathFigure StartPoint="30 10" ><LineSegment Point="20 10" /><LineSegment Point="20 30" /><LineSegment Point="30 30" /><LineSegment Point="30 10" IsStroked="False"/></PathFigure></PathGeometry></Path.Data></Path><Ellipse Width="12" Height="12" Stroke="#030303" StrokeThickness="2" Fill="Transparent" Canvas.Top="14" Canvas.Left="44"/><Ellipse x:Name="waferW" Width="40" Height="40" StrokeThickness="1" Stroke="Black" Canvas.Left="-24" Fill="Blue"Visibility="{Binding Wafer,Converter={StaticResource cvt1}}"/><!--RelativeSource={RelativeSource TemplatedParent}}"Fill="{Binding Wafer,Converter={StaticResource WaferIntToColorConverter},RelativeSource={RelativeSource TemplatedParent}}"/>--></Canvas></Canvas><Canvas x:Name="armRT1" Width="200" Height="100" Canvas.Left="0" Canvas.Top="50" RenderTransformOrigin="0.5 0.5" Background="Transparent"><Canvas.RenderTransform><RotateTransform x:Name="armRT1RotateAct"/></Canvas.RenderTransform><Canvas x:Name="armRT1Arm" Width="70" Height="30" Canvas.Left="30" Canvas.Top="35" ><Path Stroke="{StaticResource robotBorderBrush}" Fill="#FF7F50" StrokeThickness="1" StrokeEndLineCap="Round" ><Path.Data><PathGeometry><PathFigure StartPoint="0 5" IsClosed="True"><LineSegment Point="51 0"/><LineSegment Point="51 30" IsStroked="False"/><LineSegment Point="0 25"/><LineSegment Point="0 5" IsStroked="False"/></PathFigure></PathGeometry></Path.Data></Path><Path Stroke="{StaticResource robotBorderBrush}" StrokeThickness="1" Canvas.Left="0" StrokeEndLineCap="Round" StrokeStartLineCap="Round" Fill="#FF7F50"Data="M 0,5 A 10,10 0 0 0 0,25"></Path></Canvas><Canvas x:Name="armRT1Center" Width="40" Height="40" Canvas.Left="80" Canvas.Top="30" ><Path Stroke="{StaticResource robotBorderBrush}" Fill="Blue" StrokeThickness="1" StrokeEndLineCap="Round" ><Path.Data><PathGeometry><PathFigure StartPoint="0 6" IsClosed="True"><LineSegment Point="6 0"/><LineSegment Point="34 0"/><LineSegment Point="40 6"/><LineSegment Point="40 34"/><LineSegment Point="34 40"/><LineSegment Point="6 40"/><LineSegment Point="0 34"/></PathFigure></PathGeometry></Path.Data></Path></Canvas></Canvas><Canvas x:Name="armRT2" Width="70" Height="50" Canvas.Left="-95" Canvas.Top="80" Background="Transparent"><Canvas.RenderTransform><TransformGroup><TranslateTransform x:Name="armRT2Act"></TranslateTransform></TransformGroup></Canvas.RenderTransform><Canvas x:Name="armRT2Arm" Width="70" Height="20" Canvas.Left="50" Canvas.Top="10" RenderTransformOrigin="0 0.5" ><Canvas.RenderTransform><RotateTransform x:Name="armRT2ArmRotateAct"/></Canvas.RenderTransform><Path Stroke="{StaticResource robotBorderBrush}" StrokeThickness="1" Canvas.Left="70" StrokeEndLineCap="Round" StrokeStartLineCap="Round" Fill="#6495ED"Data="M 0,0 A 10,10 0 0 1 0,20"></Path><Path Stroke="{StaticResource robotBorderBrush}" StrokeThickness="1" Canvas.Left="0" StrokeEndLineCap="Round" StrokeStartLineCap="Round" Fill="#6495ED"Data="M 0,0 A 10,10 0 0 0 0,20"></Path><Path Stroke="{StaticResource robotBorderBrush}" Fill="#6495ED" StrokeThickness="1" StrokeEndLineCap="Round" ><Path.Data><PathGeometry><PathFigure StartPoint="70 0" ><LineSegment Point="0 0" /><LineSegment Point="0 20" IsStroked="False"/><LineSegment Point="70 20"/><LineSegment Point="70 0" IsStroked="False"/></PathFigure></PathGeometry></Path.Data></Path><Ellipse Width="12" Height="12" Stroke="#030303" StrokeThickness="2" Fill="Transparent" Canvas.Top="4" Canvas.Left="62"/></Canvas><Canvas x:Name="armRGripper" Height="40" Width="50" Canvas.Left="0" Canvas.Top="0" ><Path Stroke="{StaticResource robotBorderBrush}" StrokeThickness="2" StrokeEndLineCap="Round" ><Path.Data><PathGeometry><PathFigure StartPoint="30 14" ><LineSegment Point="10 14" /><LineSegment Point="4 8" /><LineSegment Point="-6 8" /></PathFigure><PathFigure StartPoint="30 26" ><LineSegment Point="10 26" /><LineSegment Point="4 32" /><LineSegment Point="-6 32" /></PathFigure></PathGeometry></Path.Data></Path><Path Stroke="{StaticResource robotBorderBrush}" Fill="#7A7E90" StrokeThickness="1" StrokeEndLineCap="Round" ><Path.Data><PathGeometry><PathFigure StartPoint="40 0" ><LineSegment Point="60 0" /><LineSegment Point="60 40" /><LineSegment Point="40 40" /><LineSegment Point="30 30" /><LineSegment Point="30 10" /><LineSegment Point="40 0" /></PathFigure></PathGeometry></Path.Data></Path><Path Stroke="{StaticResource robotBorderBrush}" Fill="#7A7E90" StrokeThickness="1" StrokeEndLineCap="Round" ><Path.Data><PathGeometry><PathFigure StartPoint="30 10" ><LineSegment Point="20 10" /><LineSegment Point="20 30" /><LineSegment Point="30 30" /><LineSegment Point="30 10" IsStroked="False"/></PathFigure></PathGeometry></Path.Data></Path><Ellipse Width="12" Height="12" Stroke="#030303" StrokeThickness="2" Fill="Transparent" Canvas.Top="14" Canvas.Left="44"/><Ellipse x:Name="waferR" Width="40" Height="40" StrokeThickness="1" Stroke="Black" Canvas.Left="-24" Fill="Blue"Visibility="{Binding Wafer,Converter={StaticResource cvt1}}"/><!--RelativeSource={RelativeSource TemplatedParent}}"Fill="{Binding Wafer,Converter={StaticResource WaferIntToColorConverter},RelativeSource={RelativeSource TemplatedParent}}"/>--></Canvas></Canvas></Canvas></Canvas></Viewbox></ControlTemplate></Setter.Value></Setter>
</Style>
使用:
private void TCWButton_Click(object sender, RoutedEventArgs e)
{robot.RobotTAction = WaferRobotTAction.T_CW;
}
通过方法里改变控件对象的属性就可以改变控件的现实状态;