我有一个锁定/解锁的挂锁图标,实现为带有一些绘图原语的复选框,这些原语由 IsChecked 上的触发器更改。它在 Blend 中运行良好。在 VS2010 和内置应用程序中,当挂锁从默认打开状态切换到关闭状态时,挂锁主体会消失,因此只有关闭的“箍”可见。箍在正确的位置 - 它确实移动,因此控件似乎确实切换了画布。切换回来时,身体再次出现。有没有人遇到过类似的/知道会发生什么?
模板;
<Canvas x:Key="PadlockClosed" Width="21" Height="21">
<Path Data="M10.668887,13.83234 C10.168442,2.3320701 20.347726,0.31172793 21.014875,13.894838" Height="9.451" Canvas.Left="2.719" Stretch="Fill" Canvas.Top="0.162" Width="10.362" StrokeThickness="2" Stroke="#FFE2E2E2"/>
<ContentPresenter Content="{DynamicResource PadlockBody}"/>
</Canvas>
<Canvas x:Key="PadlockOpen" Width="21" Height="21">
<Path Data="M10.668887,13.83234 C10.168442,2.3320701 20.347726,0.31172793 21.014875,13.894838" Height="9.451" Canvas.Left="11.102" Stretch="Fill" Canvas.Top="0.162" Width="10.362" StrokeThickness="2" Stroke="#FFE2E2E2"/>
<ContentPresenter Content="{DynamicResource PadlockBody}"/>
</Canvas>
<Canvas x:Key="PadlockBody">
<Rectangle Height="12.8" Canvas.Left="0.125" Canvas.Top="8.0" Width="15.082" RadiusX="4" RadiusY="4" RenderTransformOrigin="0.704,0.5">
<Rectangle.Fill>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<LinearGradientBrush.RelativeTransform>
<TransformGroup>
<ScaleTransform CenterY="0.5" CenterX="0.5"/>
<SkewTransform CenterY="0.5" CenterX="0.5"/>
<RotateTransform Angle="-90" CenterY="0.5" CenterX="0.5"/>
<TranslateTransform/>
</TransformGroup>
</LinearGradientBrush.RelativeTransform>
<GradientStop Color="#FF8B8989" Offset="0"/>
<GradientStop Color="White" Offset="1"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<Path Data="M15.1,16.333333 L15.1,19.750334" Height="5.417" Canvas.Left="6.375" Stretch="Fill" Stroke="Black" StrokeThickness="1" StrokeEndLineCap="Round" Canvas.Top="11.333" Width="2.167"/>
<Ellipse Height="2.5" Canvas.Left="6.125" Canvas.Top="11.333" Width="2.584" Fill="#FF0A0101"/>
</Canvas>
我用来测试的东西;
<CheckBox Template="{DynamicResource PadlockCheckBox}" Width="20" Height="20" IsChecked="True"/>
资源是动态的唯一原因是为了简化 Blend。