Hi,@Mesh Ka. Welcome Microsoft Q&A. You could directly open and close a window. You can also create a popup dialog form using a combination of controls and techniques. You could try the example here.
Create a Custom Dialog UserControl:
Start by creating a new UserControl in your WPF project. This UserControl will represent your popup dialog.
Right-click your project in Solution Explorer. Select "Add" -> "User Control (WPF)". Give it a name like "MyPopupDialog.xaml". Design Your Popup UserControl:
Design your popup dialog within the UserControl just like you would design any other window. You can add buttons, text, input fields, or any other controls that your popup needs. Set the layout and appearance as desired.
usercontrol:
<UserControl x:Class="YourNamespace.MyPopupDialog"
...
Height="200" Width="300">
<Grid>
<StackPanel>
<TextBlock Text="Popup Title" FontWeight="Bold" HorizontalAlignment="Center"/>
<TextBox PlaceholderText="sample"/>
<Button Content="OK" HorizontalAlignment="Center" Click="OKButton_Click"/>
<Button Content="Cancel" HorizontalAlignment="Center" Click="CancelButton_Click"/>
</StackPanel>
</Grid>
</UserControl>
UserControl.xaml.cs:
public partial class MyPopupDialog : UserControl
{
public MyPopupDialog()
{
InitializeComponent();
}
private void OKButton_Click(object sender, RoutedEventArgs e)
{
// Handle OK button click here
// Close the popup or perform other actions
}
private void CancelButton_Click(object sender, RoutedEventArgs e)
{
// Handle Cancel button click here
// Close the popup or perform other actions
}
}
To show the popup dialog, you could create an instance of your MyPopupDialog UserControl and place it inside a Popup control. You can then open and close the Popup as needed.
MainWindow.xaml:
<Grid>
<!-- Your main content -->
<Button Content="Open Popup" Click="OpenPopup_Click"/>
<Popup Name="popup" IsOpen="False" StaysOpen="False" Placement="Center">
<local:MyPopupDialog/>
</Popup>
</Grid>
MainWindow.xaml.cs:
private void OpenPopup_Click(object sender, RoutedEventArgs e)
{
popup.IsOpen = true; // Open the popup
}
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.