4
내가 만든 사용자 지정 연결된 이벤트를 사용하고 있는데 내가 여기에이 이벤트
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void dataGridTasks_Drop(object sender, RoutedEventArgs e)
{
}
}
XAML 코드
<ListView util:DragDropHelper.Drop="dataGridTasks_Drop">
I에 처리기를 추가하기 위해 노력하고있어
에 대한 런타임시 InitializeComponent에서이 오류가 발생했습니다.
'System.String'유형의 객체는 을유형으로 변환 할 수 없습니다.'System.Windows.RoutedEventHandler'.
누구나 내가 왜이 오류가 발생하는지 알 수 있습니까? 감사합니다. 여기
내 이벤트 코드
public static readonly RoutedEvent DropEvent = EventManager.RegisterRoutedEvent(
"Drop", RoutingStrategy.Bubble, typeof(DropEventArgs), typeof(DragDropHelper));
public static void AddDropHandler(DependencyObject d, RoutedEventHandler handler)
{
UIElement uie = d as UIElement;
if (uie != null)
{
uie.AddHandler(DragDropHelper.DropEvent, handler);
}
}
public static void RemoveDropHandler(DependencyObject d, RoutedEventHandler handler)
{
UIElement uie = d as UIElement;
if (uie != null)
{
uie.RemoveHandler(DragDropHelper.DropEvent, handler);
}
}
DropEventArgs 코드
샘플 내 코드를 확인 몇 시간의 문제는 실제로 이벤트의 이벤트 정의이었다 후class DropEventArgs : RoutedEventArgs
{
public object Data { get; private set; }
public int Index { get; private set; }
public DropEventArgs(RoutedEvent routedEvent, object data, int index)
: base(routedEvent)
{
Data = data;
Index = index;
}
}
디자이너 대신 코드에서 이벤트 처리기를 연결해 보았습니까? –
시도하지 않았지만 코드 뒤에 작동 할 수도 있습니다. 하지만 xaml 코드에서 작동하지 않는 이유는 무엇입니까? 특별히 내가 온라인에서 찾은 모든 예가 그렇게 작동한다는 것을 알 수 있습니다. – Zied
이벤트 정의 방법을 말씀해 주시겠습니까? – mg007