优化代码
This commit is contained in:
@@ -440,16 +440,14 @@ namespace Ink_Canvas.Windows
|
||||
|
||||
private void ToggleSwitch_Click(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
var border = sender as Border;
|
||||
if (border != null)
|
||||
if (sender is Border border)
|
||||
{
|
||||
// 切换开关状态
|
||||
bool isOn = border.Background.ToString() == "#FF3584E4";
|
||||
border.Background = isOn ? new SolidColorBrush(Color.FromRgb(225, 225, 225)) : new SolidColorBrush(Color.FromRgb(53, 132, 228));
|
||||
|
||||
// 切换内部圆点的位置
|
||||
var innerBorder = border.Child as Border;
|
||||
if (innerBorder != null)
|
||||
if (border.Child is Border innerBorder)
|
||||
{
|
||||
innerBorder.HorizontalAlignment = isOn ? HorizontalAlignment.Left : HorizontalAlignment.Right;
|
||||
}
|
||||
@@ -557,8 +555,7 @@ namespace Ink_Canvas.Windows
|
||||
|
||||
private void OptionButton_Click(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
var border = sender as Border;
|
||||
if (border != null)
|
||||
if (sender is Border border)
|
||||
{
|
||||
string tag = border.Tag?.ToString();
|
||||
if (!string.IsNullOrEmpty(tag))
|
||||
@@ -568,8 +565,7 @@ namespace Ink_Canvas.Windows
|
||||
|
||||
// 设置当前按钮为选中状态
|
||||
border.Background = new SolidColorBrush(Color.FromRgb(225, 225, 225));
|
||||
var textBlock = border.Child as TextBlock;
|
||||
if (textBlock != null)
|
||||
if (border.Child is TextBlock textBlock)
|
||||
{
|
||||
textBlock.FontWeight = FontWeights.Bold;
|
||||
}
|
||||
@@ -583,8 +579,7 @@ namespace Ink_Canvas.Windows
|
||||
private void ClearOtherOptionsInGroup(Border currentBorder, string currentTag)
|
||||
{
|
||||
// 获取当前按钮所在的父容器
|
||||
var parent = currentBorder.Parent as StackPanel;
|
||||
if (parent != null)
|
||||
if (currentBorder.Parent is StackPanel parent)
|
||||
{
|
||||
// 获取组名(Tag中下划线前的部分)
|
||||
string groupName = currentTag.Split('_')[0];
|
||||
@@ -598,8 +593,7 @@ namespace Ink_Canvas.Windows
|
||||
if (!string.IsNullOrEmpty(childTag) && childTag.StartsWith(groupName + "_"))
|
||||
{
|
||||
border.Background = new SolidColorBrush(Colors.Transparent);
|
||||
var textBlock = border.Child as TextBlock;
|
||||
if (textBlock != null)
|
||||
if (border.Child is TextBlock textBlock)
|
||||
{
|
||||
textBlock.FontWeight = FontWeights.Normal;
|
||||
}
|
||||
@@ -776,8 +770,7 @@ namespace Ink_Canvas.Windows
|
||||
|
||||
if (child is Border border && border.Background != null)
|
||||
{
|
||||
var brush = border.Background as SolidColorBrush;
|
||||
if (brush != null && brush.Color.ToString() == "#FFDEDEDE")
|
||||
if (border.Background is SolidColorBrush brush && brush.Color.ToString() == "#FFDEDEDE")
|
||||
{
|
||||
return border;
|
||||
}
|
||||
@@ -800,8 +793,7 @@ namespace Ink_Canvas.Windows
|
||||
|
||||
if (child is Border border && border.Background != null)
|
||||
{
|
||||
var brush = border.Background as SolidColorBrush;
|
||||
if (brush != null && brush.Color.ToString() == "#FF3584E4")
|
||||
if (border.Background is SolidColorBrush brush && brush.Color.ToString() == "#FF3584E4")
|
||||
{
|
||||
return border;
|
||||
}
|
||||
@@ -959,8 +951,7 @@ namespace Ink_Canvas.Windows
|
||||
var relativePosition = Math.Max(0, Math.Min(1, adjustedX / effectiveWidth));
|
||||
|
||||
// 更新滑块位置
|
||||
var thumbTransform = customSlider.ThumbImage.RenderTransform as TranslateTransform;
|
||||
if (thumbTransform == null)
|
||||
if (!(customSlider.ThumbImage.RenderTransform is TranslateTransform thumbTransform))
|
||||
{
|
||||
thumbTransform = new TranslateTransform();
|
||||
customSlider.ThumbImage.RenderTransform = thumbTransform;
|
||||
|
||||
Reference in New Issue
Block a user