开发者

WPF: Can't drop filename in textbox

I'm trying to drop a file into a textbox on my WPF application but it won't work. I believe I have the XAML setup correctly to do this, and a PreviewDragOver event handler does work-- just not Drop or PreviewDrop. Here's the XAML in question:

<Window x:Class="TableTagCount.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525" AllowDrop="True">
<Grid Name="bgGrid" Drop="bgGrid_Drop" AllowDrop="True">
    <Grid.Background>
        <ImageBrush ImageSource="/TableTagCount;component/Images/Sunset.jpg" Stretch=开发者_C百科"Fill" TileMode="None" />
    </Grid.Background>
    <Button Content="Analyze" Height="23" HorizontalAlignment="Left" Margin="32,91,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click"/>
    <TextBox Height="23"  HorizontalAlignment="Left" Margin="32,43,0,0" Name="textBox1" VerticalAlignment="Top" Width="205"  PreviewDragOver="textBox1_PreviewDragOver" AllowDrop="True" />
    <Label Content="File Name" Height="28" HorizontalAlignment="Left" Margin="32,13,0,0" Name="label1" VerticalAlignment="Top" Width="65" />
</Grid></Window>

Note that the Drop operation does work on my Grid.

Also, I'd like to prevent the Drop event from being handled by the Grid if my textbox handles it first. In my textbox Drop handler I'm setting the DragEventArg's Handled property to true. Is this enough to keep the event from bubbling up to the Grid?


First, I don't see a Drop handler on your TextBox. Could that be the reason it doesn't work? ;-)

Second, yes, setting Handled to true should be enough to stop bubbling.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜