如何在wpf应用程序中使用弹出窗口?

时间:2011-08-16 08:16:02

标签: wpf xaml gridview popup telerik

我有6个窗口,在每个窗口中我都有一个gridview来显示实体列表,在gridview下我有三个按钮(添加,编辑,删除)。我想当用户点击删除按钮弹出窗口打开并显示此操作的结果(成功或错误)。 在所有窗口中都执行了此操作。 我的问题是,它是向用户显示弹出消息的最佳方式(根据我的代码)? 我相信有更好的方法可以做到这一点。

  

<DockPanel>
    <Popup Name="SuccessPopup" StaysOpen="False" PlacementTarget="{Binding ElementName=menu}" Placement="Relative" Width="{Binding ActualWidth, ElementName=grdCustomers}" PopupAnimation="Fade" AllowsTransparency="True">
        <Border BorderBrush="#0D8E16" BorderThickness="2.5" Background="#DFF3D6">
            <TextBlock Margin="10" FontSize="12" FontFamily="Tahoma" Text="مشتری مورد نظر با موفقیت حذف شد." TextAlignment="Center" />
        </Border>
    </Popup>
    <Popup Name="ErrorPopup" StaysOpen="False" PlacementTarget="{Binding ElementName=menu}" Placement="Relative" Width="{Binding ActualWidth, ElementName=grdCustomers}" PopupAnimation="Fade" AllowsTransparency="True">
        <Border BorderBrush="#B30000" BorderThickness="2.5" Background="#FFDBDB">
            <TextBlock Margin="10" FontSize="12" FontFamily="Tahoma" Text="متاسفانه مشکلی در حین حذف مشتری مورد نظر به وجود آمد." TextAlignment="Center" />
        </Border>
    </Popup>        
    <telerik:RadMenu Name="menu" ItemClick="menu_ItemClick" DockPanel.Dock="Top" TabIndex="0">
        <telerik:RadMenuItem Header="{x:Static sr:ControlResource.File}">
            <telerik:RadMenuItem Header="{x:Static sr:ControlResource.Export}">
                <telerik:RadMenuItem Header="{x:Static sr:ControlResource.HtmlExport}" Name="mnuHtmlExport" />
                <telerik:RadMenuItem Header="{x:Static sr:ControlResource.ExcelExport}" Name="mnuExcelExport" />
                <telerik:RadMenuItem Header="{x:Static sr:ControlResource.WordExport}" Name="mnuWordExport" />
                <telerik:RadMenuItem Header="{x:Static sr:ControlResource.CsvExport}" Name="mnuCsvExport" />
            </telerik:RadMenuItem>
        </telerik:RadMenuItem>
    </telerik:RadMenu>

    <Border Background="#FFF4F5F3" BorderBrush="#FF9E9A9A" DockPanel.Dock="Bottom" BorderThickness="1" Grid.Row="4" Margin="0">
        <Grid DataContext="{Binding ElementName=grdCustomers, Path=SelectedItem}">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="1*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
                <RowDefinition Height="1*" />
            </Grid.RowDefinitions>

            <Label Name="lblName" Content="{x:Static sr:CustomerResource.Name}" Foreground="#FF3E3E3E" Grid.Column="1" />
            <Label Name="lblTel" Content="{x:Static sr:CustomerResource.Tel}" Foreground="#FF3E3E3E" Grid.Column="1" Grid.Row="1" />
            <Label Name="lblMobile" Content="{x:Static sr:CustomerResource.Mobile}" Foreground="#FF3E3E3E" Grid.Column="1" Grid.Row="2" />
            <Label Name="lblAddress" Content="{x:Static sr:CustomerResource.Address}" Foreground="#FF3E3E3E" Grid.Column="1" Grid.Row="3" />

            <telerik:RadMaskedTextBox Name="txtName" Value="{Binding Path=Name}" Grid.Row="0" HorizontalAlignment="Right" IsReadOnly="True" Margin="0,6,6,6" Width="200" TabIndex="4" />
            <telerik:RadMaskedTextBox Name="txtTel" Value="{Binding Path=Tel}" Grid.Row="1" HorizontalAlignment="Right" IsReadOnly="True" Margin="0,6,6,6" Width="100" TabIndex="5" />
            <telerik:RadMaskedTextBox Name="txtMobile" Value="{Binding Path=Mobile}" Grid.Row="2" HorizontalAlignment="Right" IsReadOnly="True" Margin="0,6,6,6" Width="100" TabIndex="6" />
            <telerik:RadMaskedTextBox Name="txtAddress" Value="{Binding Path=Address}" Grid.Row="3" HorizontalAlignment="Right" IsReadOnly="True" Margin="0,6,6,6" Width="350" TabIndex="7" />

            <Border Style="{StaticResource ButtonsBorder}" Grid.Row="4" Grid.ColumnSpan="2">
                <StackPanel Orientation="Horizontal">
                    <Button Name="btnAddNewCustomer" Content="{x:Static sr:ControlResource.AddNewCustomer}" TabIndex="8" Width="120" Height="23" Margin="8,8,6,8" Click="btnAddNewCustomer_Click" />
                    <Button Name="btnEdit" IsEnabled="{Binding ElementName=grdCustomers, Path=HasItems}" Content="{x:Static sr:ControlResource.Edit}" TabIndex="9" Width="100" Height="23" Margin="0,8,6,8" Click="btnEdit_Click" />
                    <Button Name="btnDelete" IsEnabled="{Binding ElementName=grdCustomers, Path=HasItems}" Content="{x:Static sr:ControlResource.Delete}" TabIndex="10" Width="100" Height="23" Margin="0,8,6,8" Click="btnDelete_Click" />
                </StackPanel>
            </Border>
        </Grid>
    </Border>

    <telerik:RadDataPager Name="dataPager" Grid.Row="3" PageSize="20" DockPanel.Dock="Bottom" TabIndex="2" />

    <telerik:RadGridView Grid.Row="1" ItemsSource="{Binding PagedSource, ElementName=dataPager}" Name="grdCustomers" TabIndex="1" >
        <telerik:RadGridView.Columns>
            <telerik:GridViewDataColumn Header="{x:Static sr:CustomerResource.ID}" DataMemberBinding="{Binding ID}" MinWidth="50" MaxWidth="100" Background="#FFF8DD" />
            <telerik:GridViewDataColumn Header="{x:Static sr:CustomerResource.Name}" DataMemberBinding="{Binding Name}" MinWidth="200" />
            <telerik:GridViewDataColumn Header="{x:Static sr:CustomerResource.Tel}" DataMemberBinding="{Binding Tel}" MinWidth="150" />
            <telerik:GridViewDataColumn Header="{x:Static sr:CustomerResource.Mobile}" DataMemberBinding="{Binding Mobile}" MinWidth="150" Width="*" />
        </telerik:RadGridView.Columns>
    </telerik:RadGridView>
</DockPanel>

1 个答案:

答案 0 :(得分:1)

您只需将窗口显示为弹出窗口,如下所示:

MyPopUp dlg = new MyPopUp();
dlg.ShowDialog();

在按钮的Click事件处理程序中执行此操作。