开发者

How to use popup in wpf application?

I have 6 window that in each one of them i have a gridview to show a list of entities and under the gridview i have three button (Add, Edit, Delete). i want when a user clicked in Delete button a popup Opens and show the result of this action (Success or Error). In all of windows this action performed. My Question is that is it the best way to show a popup message to the user(According to my code)? I believe there is a better way for doing this.

<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" ItemsS开发者_StackOverflowource="{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>


You can simply show a Window as a pop-up as follows:

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

Do this in the Click event handler for your buttons.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜