문제:
System.Windows.Markup.XamlParseException InvalidCastException: Unable to cast object of type 발생
조건:
1. ItemsControl의 ItemsPanelTemplate에 커스텀 컨트롤 사용
2. 해당 커스텀 컨트롤에 DragDrop.Drop 이벤트 연결
3. ItemsControl 바깥에 TextBlock이 존재
예시:
<Window x:Class="Test.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Test"
xmlns:CustomCtrl="clr-namespace:Test.CustomCtrl"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<ItemsControl x:Name="ItemCtrl" Background="Transparent" IsTabStop="False">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<CustomCtrl:CustomList x:Name="List" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Orientation="Vertical" AllowDrop="True" DragDrop.Drop="List_Drop"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
<TextBlock x:Name="Block" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Grid>
</Window>
CustomList는 기본 VirtualStackPanel임
임시 해결:
DragDrop.Drop 이벤트 대신 Drop 이벤트를 사용
기타:
실행 시에만 오류 발생
특이하게 오류는 TextBlock에 표시되지만 ItemsPanelTemplate의 DragDrop.Drop 부분을 수정해야 오류가 사라짐
반응형
'Code > WPF' 카테고리의 다른 글
WPF Binding 디버깅 (0) | 2021.11.12 |
---|---|
작업표시줄/Alt+Tab 에서 Window 숨기기 (0) | 2021.10.27 |
Visibility와 Focus (0) | 2021.10.17 |
WPF TreeViewItem Stretch (0) | 2021.10.15 |
WPF DragDrop이 작동하지 않음 (0) | 2021.09.25 |
WPF MouseUp시 입력된 버튼 찾기 (0) | 2021.09.01 |
WPF 마우스 이벤트가 작동하지 않는 문제 (0) | 2021.08.26 |
WPF 최대화 문제 (0) | 2021.08.21 |