重新绑定DataGrid后弹出窗口没有打开

时间:2014-10-03 17:28:13

标签: wpf

我最近开始研究WPF。目前我正面临一个问题。 我有一个窗口,里面有一个用户控件,包含DataGrid,Combobox,按钮和弹出窗口。 我正在使用删除按钮将DataGrid与Notes列表(字符串)绑定。因此,当我们单击该按钮时,弹出窗口将打开,弹出窗口将显示带有是或否按钮的确认消息。 当我单击是按钮时,我将删除注释并仅重新绑定DataGrid.And之后,当我单击删除按钮时弹出窗口没有打开。

如果我没有重新绑定DataGrid,那么PopUp正在打开但是问题被删除注意仍然存在于DataGrid中但是从数据库中删除了,这会混淆注释是否被删除。这就是我重新绑定的原因。

但Rebinding导致无法打开Popup的问题。

请帮助我如何完成这项工作。

我的弹出窗口看起来像这样:

<Popup x:Name="Popupdelete"                                        
           AllowsTransparency="True"
           HorizontalOffset="-10" 
           VerticalOffset="10"
           Placement="Mouse"
           StaysOpen="False"
           IsOpen="{Binding IsDeletePopUpOpen}">
        <Grid x:Name="LayoutRoot" Background="Transparent" Height="105">
                <!-- My confirmation message and Yes No button goes Here-->
        </Grid>

IsDeletePopUpOpen在ViewModel中设置。

谢谢&amp;问候, 喜悦

1 个答案:

答案 0 :(得分:0)

代码在这里:

&lt; - 删除弹出窗口 - &gt;

  <Popup x:Name="Popupdelete"                                        
           AllowsTransparency="True"
           HorizontalOffset="-10" 
           VerticalOffset="10"
           Placement="Mouse"
           StaysOpen="False"
           IsOpen="{Binding IsDeletePopUpOpen}">
    <Grid x:Name="LayoutRoot" Background="Transparent" Height="105">
            <Border BorderBrush="#E2E2E2" BorderThickness="6" Background="White">
                <Grid>
                    <TextBlock TextWrapping="Wrap" Margin="10,10,10,50" Foreground="#454545" FontWeight="SemiBold" HorizontalAlignment="Center" VerticalAlignment="Center" Height="30" Width="Auto" Text="Are you sure you want" />
                    <TextBlock TextWrapping="Wrap" Margin="50,15,50,25" Foreground="#454545" FontWeight="SemiBold" HorizontalAlignment="Center" VerticalAlignment="Center" Height="30" Width="Auto" Text="to delete?"/>
                    <Button Content="Yes"  Margin="35,50,80,0" Height="40" HorizontalAlignment="Center" VerticalAlignment="Center" Command="{Binding DeleteYesCmd}" CommandParameter="{Binding SelectedItem, ElementName=lstCustomer}"  Style="{StaticResource SaveButtonStyle}" />
                    <TextBlock Text="or" Margin="75,50,60,15"   HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="#919191" FontSize="10"  />
                    <TextBlock  Margin="95,48,35,12"  HorizontalAlignment="Center" VerticalAlignment="Center" ><Hyperlink  Command="{Binding DeleteNoCmd}"><Run Text="No"  FontWeight="Bold" FontSize="12"/></Hyperlink></TextBlock>
                </Grid>
            </Border>
        </Grid>
   </Popup>

&lt; - 删除图像按钮的便笺列表 - &gt;

                            <Border Background="#F0F0F0" CornerRadius="0"  Visibility="{Binding NotesListViewVisibility}">
                                <ScrollViewer x:Name="scrollMe" CanContentScroll="True" Height="80" >
                                    <Border Background="White" CornerRadius="5,0,0,5">
                                        <Grid Background="White" Margin="5">
                                            <Grid.ColumnDefinitions>
                                                <ColumnDefinition Width="101*"/>
                                                <ColumnDefinition Width="35*"/>
                                            </Grid.ColumnDefinitions>
                                            <ListView x:Name="lstCustomer"  BorderBrush="Transparent" BorderThickness="0" ScrollViewer.CanContentScroll="True" 
                            ScrollViewer.HorizontalScrollBarVisibility="Disabled" RequestBringIntoView="RemoveScrollViewFocus" 
                    ItemsSource="{Binding OutcomeNotesView , Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" ScrollViewer.VerticalScrollBarVisibility="Disabled" SelectionMode="Single"  
                    Background="#FFFFFF" ItemContainerStyle="{StaticResource ListviewItemContainerStyle}" Grid.ColumnSpan="2">
                                                <ListView.ItemsPanel>
                                                    <ItemsPanelTemplate>
                                                        <UC:NoteStackPanel/>
                                                    </ItemsPanelTemplate>
                                                </ListView.ItemsPanel>
                                                <ListView.ItemTemplate>
                                                    <DataTemplate>
                                                        <StackPanel>
                                                            <Border BorderBrush="#E6E6E6" BorderThickness="0,0,0,1" 
                                                                Width="{Binding ActualWidth, Converter={StaticResource widthconv}, ElementName=lstCustomer}">
                                                                <StackPanel x:Name="spNotes"  Orientation="Vertical" Margin="0,10,0,10" >
                                                                    <Grid>
                                                                        <Grid.ColumnDefinitions>
                                                                            <ColumnDefinition Width="auto"/>
                                                                            <ColumnDefinition Width="*"/>
                                                                        </Grid.ColumnDefinitions>

                                                                        <StackPanel Grid.Row="0" Grid.Column="0" HorizontalAlignment="Left" Orientation="Horizontal">
                                                                            <Button x:Name="btnPrimaryOfficer" MouseEnter="SetEmployeePopUpPlacement" Style="{StaticResource AuthButton}"
                                                                                CommandParameter="{Binding}" Command="{Binding DataContext.OutcomeEmployeePopUp, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListView}}}">
                                                                                <Button.Visibility>
                                                                                    <MultiBinding Converter="{StaticResource ActiveInactiveConv}" ConverterParameter="Hyper">
                                                                                        <Binding Path="EmployeeInfo.ActiveStatusCode"/>
                                                                                        <Binding Path="EmployeeInfo.Id"/>
                                                                                    </MultiBinding>
                                                                                </Button.Visibility>
                                                                                <Button.InputBindings>
                                                                                    <MouseBinding Gesture="LeftDoubleClick" CommandParameter="{Binding}"
                                                                                        Command="{Binding DataContext.OutcomeEmployeePopUp, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListView}}}"/>
                                                                                </Button.InputBindings>
                                                                                <StackPanel Orientation="Horizontal">
                                                                                    <Image Source="{StaticResource imgUser}" Width="15" Height="15" HorizontalAlignment="Left" />
                                                                                    <TextBlock Text="{Binding EmployeeInfo.Name}"  Style="{StaticResource AuthEditProfile}" FontFamily="{StaticResource FontBold}" FontSize="12" Margin="2,0,0,0" />
                                                                                </StackPanel>
                                                                            </Button>
                                                                            <StackPanel Orientation="Horizontal" >
                                                                                <StackPanel.Visibility>
                                                                                    <MultiBinding Converter="{StaticResource ActiveInactiveConv}" ConverterParameter="Normal">
                                                                                        <Binding Path="EmployeeInfo.ActiveStatusCode"/>
                                                                                        <Binding Path="EmployeeInfo.Id"/>
                                                                                    </MultiBinding>
                                                                                </StackPanel.Visibility>
                                                                                <!--Visibility="{Binding PrimaryOfficerActiveStatusCode,Converter={StaticResource ActiveInactiveConv},ConverterParameter=Normal}">-->
                                                                                <Image Source="{StaticResource imgUserBlack}" Width="15" Height="15" HorizontalAlignment="Left" />
                                                                                <TextBox Text="{Binding EmployeeInfo.Name}" Style="{StaticResource TextWithoutHyperlink}" Margin="2,0,0,0" />
                                                                            </StackPanel>
                                                                            <TextBlock Background="Transparent"  Text="on" 
                                                                             FontFamily="{StaticResource FontMedium}" FontSize="12" Foreground="#919191" Margin="4,0,2,0" 
                                                                             VerticalAlignment="Bottom" HorizontalAlignment="Center"/>
                                                                            <TextBox Text="{Binding AddedDate, StringFormat=\{0:MM/dd/yy\}}" Foreground="#454545" VerticalAlignment="Bottom"  MaxLength="{Binding Length}"
                                                                             HorizontalAlignment="Center" Margin="2,0,0,0" Style="{StaticResource ContentText}"/>
                                                                        </StackPanel>
                                                                        <StackPanel Grid.Column="1" Grid.Row="0" HorizontalAlignment="Right" Visibility="{Binding DataContext.DeleteNoteVisibility, ElementName=OutcomeNotesView}" Orientation="Horizontal">
                                                                            <StackPanel Orientation="Horizontal" >
                                                                                <Button x:Name="btnDelete" Width="Auto" MouseEnter="btnDelete_MouseEnter" MouseLeave="btnDelete_MouseLeave"
                                                                            CommandParameter="{Binding}"
                                                                                    Command="{Binding DataContext.LoadDeletePopUp, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListView}}}"
                                                                           Style="{StaticResource AuthButton}">
                                                                                    <StackPanel Orientation="Horizontal">
                                                                                        <Image Source="{StaticResource imgdeleteicon}" Style="{StaticResource AuthImage}"/>
                                                                                    </StackPanel>
                                                                                </Button>
                                                                            </StackPanel>
                                                                        </StackPanel>
                                                                    </Grid>
                                                                    <StackPanel >
                                                                        <TextBox Text="{Binding Note}" Foreground="#454545" TextWrapping="Wrap" Height="Auto" 
                                                                            Width="{Binding ActualWidth, Converter={StaticResource widthconv}, ElementName=lstCustomer}"
                                                                 Style="{StaticResource ContentText}" FontFamily="{StaticResource FontNormal}" FontSize="12" Padding="0"/>
                                                                        <TextBlock x:Name="txtSavingNoteId" Visibility="Collapsed" Text="{Binding NoteId}" />
                                                                    </StackPanel>
                                                                </StackPanel>
                                                            </Border>
                                                        </StackPanel>
                                                    </DataTemplate>
                                                </ListView.ItemTemplate>
                                            </ListView>
                                        </Grid>
                                    </Border>
                                </ScrollViewer>
                            </Border>
                        </StackPanel>
    public List<ActivityNotesDto> OutcomeNotesView
    {
        get
        {
            return outcomeNotesView;
        }
        set
        {
            outcomeNotesView = value;
            OnPropertyChanged("OutcomeNotesView");
        }
    }

DeleteActivityNote(deletingNoteDetails);

OutcomeNotesView = GetActivityNotesList();

如果我遗失了某些内容,请告诉我。自从我第一次点击按钮后,“删除”弹出窗口正在打开并且正在删除,但下次单击“删除”图像时,它没有打开弹出窗口。

谢谢&amp;问候, 喜悦