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

40 lines
1.1 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 ScreenToViewModelConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null) return null;
var viewModelType = value.GetType();
var viewName = viewModelType.FullName.Replace("ViewModel", "View");
var viewType = Type.GetType(viewName);
if (viewType != null)
{
// 创建View实例并设置其DataContext为当前的ViewModel
var view = (FrameworkElement)Activator.CreateInstance(viewType);
view.DataContext = value;
return view;
}
return null;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}