Files
test_demo/MX-PD-盘古 - new/PanGu.DieBonderApp/MainShell/Converter/WidthToMarginConverter.cs
Shi.Ji e31d3560bb 添加 MX-PD-盘古 项目文件
将 MX-PD-盘古 - new 目录下的所有文件添加到主仓库
2026-05-18 11:43:09 +08:00

44 lines
1.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;
namespace MainShell.Converter
{
public class WidthToMarginConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
double actualWidth = 0;
if (value is double d) actualWidth = d;
double expanded = 200;
double extra = 0;
if (parameter is string s)
{
var parts = s.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
if (parts.Length >= 1 && double.TryParse(parts[0], out var p0)) expanded = p0;
if (parts.Length >= 2 && double.TryParse(parts[1], out var p1)) extra = p1;
}
// 计算右侧 Margin
// 当 actualWidth == expanded 时返回 0不偏移
// 当 actualWidth 减小时会返回正值,从而把 ToggleButton 向左推(或根据需要调整公式)
double right = Math.Max(0, expanded - actualWidth) + extra;
// 根据布局需要你可以修改这里返回的 Thickness 的哪一项Left/Right
return new Thickness(-30, 0, 0, 0);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}