Google has finally failed me. I have looked everywhere I can think of but to no avail. In my project I have an image control I would like to drop pictures onto and have their filepath saved in a variable and the image displayed in the control.
After several attempts to make it work I decided to open a new project and simplify everything. Right now it seems to boil down to the Drop Event not firing on the Image Control while it does fire on a TextBlock Control.
<Window x:Class="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:VB" mc:Ignorable="d" Title="MainWindow" Height="450" Width="800"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="1*"/> <RowDefinition Height="1*"/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="1*"/> <ColumnDefinition Width="1*"/> </Grid.ColumnDefinitions> <TextBlock Grid.Column="1" AllowDrop="True" Drop="TextBlock_Drop"/> <Image AllowDrop="True" Drop="Image_Drop"/> </Grid>
Class MainWindow Private Sub TextBlock_Drop(sender As Object, e As DragEventArgs) MessageBox.Show("fired") End Sub Private Sub Image_Drop(sender As Object, e As DragEventArgs) MessageBox.Show("fired") End Sub End Class
Doesn't matter the file type. Every file dropped on the TextBlock results in the MessageBox opening. Every file dropped on the Image Control does absolutely nothing.
I have no clue why and any suggestions would be appreciated!
EDIT: Thanks to suggestions from Bulutay Saraç in his comments below I found that adding a stock Image file to the project and referencing it as the source for the Image control fixed the issue and the event now fires properly. For those who do not wish to add a default image file see Bulutay Saraç's answer below for a simple and effective work around.