WPF拖放,用户控制变得无响应

时间:2011-05-11 15:01:48

标签: c# wpf

我正在对包含ListBoxUserControl作为ClaimSectionTemplate的两个DataTemplate项目进行一些拖放,以填充源代码中的项目列表框。

现在我在ClaimSectionTemplateAddFieldRemoveField上有两个按钮,它们分别在ClaimSection对象上的子集合中添加和删除字段ClaimSectionTemplate用户控件。

所以当我将ClaimSection放入目标ListBox时,原始对象变得无法响应,不再允许我与用户控件进行交互。

MainWindow.Xaml                                                                                                                                                                                                         

        <ListBox Margin="13,12,12,12" Name="NewSections" Grid.Column="1" AllowDrop="True" Drop="NewSections_Drop">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <me:ClaimSectionTemplate />
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </Grid>
</Window>

Main Window Drag Drop Handlers

private void ExistingSections_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        var parent = (ListBox)sender;

        dragSource = parent;

        var data = ExistingSections.SelectedItem;

        if (data != null)
        {
            DragDrop.DoDragDrop(parent, data, DragDropEffects.Move);
        }
    }

    private void NewSections_Drop(object sender, DragEventArgs e)
    {
        Models.ClaimSection dropData = (Models.ClaimSection)e.Data.GetData(typeof(Models.ClaimSection));
        ClaimSectionsNew.addClaimSection(dropData);
        ClaimSectionsExisting.removeClaimSection(dropData);
    }

ClaimSectionTemplate.xaml

<UserControl x:Class="InsuranceBuildVer1.Views.ClaimSectionTemplate"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="187" d:DesignWidth="300">
    <Grid Height="185">
        <TextBlock Height="23" Margin="12,12,12,0" Name="textBlock1" Text="{Binding Path=ClaimType}" VerticalAlignment="Top"  />
        <ListBox x:Name="FieldList" HorizontalAlignment="Left" Margin="10,71,0,12" Width="278" ItemsSource="{Binding Path=Fields.ClaimFields, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">

            <ListBox.ItemTemplate>
                <DataTemplate>
                    <TextBox Text="{Binding Path=Identifier}" />
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
        <Button Content="Add Field" Height="23" HorizontalAlignment="Left" Margin="12,42,0,0" Name="AddField" VerticalAlignment="Top" Width="75" Click="AddField_Click" />
        <Button Content="Remove Field" Height="23" HorizontalAlignment="Left" Margin="103,42,0,0" Name="RemoveField" VerticalAlignment="Top" Width="96" Click="RemoveField_Click" />
    </Grid>
</UserControl>

0 个答案:

没有答案