我正在使用以下代码通过向 Thumb 添加模板控件来创建可拖动控件。但是,我需要在创建的 FilePickerPopup 对象上调用方法以设置委托等。如何访问创建的对象?下面显示的方法无法获取实际对象。
有没有比这更简单的方法来创建可拖动的 UserControl?据我了解,这可能是一种已弃用的方法。谢谢。
filePicker = new Thumb();
ControlTemplate template = new ControlTemplate();
var filePickerControl = new FrameworkElementFactory(typeof(Controls.Popups.FilePickerPopup));
filePickerControl.Name = "FilePickerControl";
template.VisualTree = filePickerControl;
filePicker.Template = template;
FilePickerPopup fpp = filePicker.Template.FindName("FilePickerControl", filePicker) as FilePickerPopup;
fpp.SetParent(parent);
注意 FilePickerPopup 有一个公共方法 SetParent(object parent);