WPF app cant load image and related info into second form - wpf

Hey everyone i need help with a WPF app im writing.
it consists of 2 forms a main input window and a script(pharmacy script app) window
on the main input window it has a combobox with 2 items : clicks and dischem, depending on what is chosen there it needs to load the logo of that pharmacy into the script window.
at the top of the script window it has an image control
how can i accomplish this?

private void Button_Click(object sender, RoutedEventArgs e)
{
if (PharmacyComboBox.SelectedItem != null)
new Window2(PharmacyComboBox.SelectedItem as Image).Show();
}

Related

Display MessageBox inside WPF window instead of center of the screen in WPF

How to display a message box inside WPF windows? Below is the code I have used to display message box but the message box always displays at the center of the screen instead of inside the WPF form. Is this possible with MessageBox? An alternate way is to use my own custom form to display the message but if possible I would like to use MessageBox. Thanks!
private void Button1_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show(this,"The record is saved successfully", "Save", MessageBoxButton.OK, MessageBoxImage.Information);
}

WinForm progressbar not working when I open that form in Wpf application?

I created a Windows form project in Visual studio and used a progress bar with style as marquee and I created another wpf project and added windows project reference to the newly created wpf project and call the form in a button click event as
private void Button_Click(object sender, RoutedEventArgs e)
{
Form1 form = new Form1();
form.Show();
}
But the progress bar inside the form is not working.
I fixed the above issue by adding the following lines
System.Windows.Forms.Application.EnableVisualStyles();
System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false);

WPF - Toggle Visibility of multiple windows

i will first explain the UI of my WPF App.
I have created a window which contains many buttons which is always visible to the user(lets call it main window), each button will open a new window relevant to the task. what i want done is that whenever a button is clicked, the main window should be hidden(visibility : collapsed) and the new window should be shown. This second window will also contain a button which will hide the second window and show back the main window.
also the second window which will be opening will have different dimensions as per the command associated with it so i will be having different windows for eaach
TLDR i want to be able to switch between multiple windows such that only one window is visible at one time, how do i manage the switching between multiple windows ??
Note : I can show the second window from main window but what about showing main from the second window....can't get it....or if anyone can show me a different approach to implement this : other than multiple windows
Also, this is an extension to the UI, i want to show the buttons in this crystalised sort of look like on this page : http://postimage.org/image/4yibiulsh/
can anyone direct me to a proper implementation, i have been through many sites and also tried to create these through blend but i just am not a UI Person....pls need help on this
Thanks in advance.
I would create a "Window manager" which will subscribe to the changes of opening/closing.
In this case you don't have to overload Window classes.
Example (worked for me).
public class WindowsManager
{
static readonly List<Window> Windows=new List<Window>();
public static T CreateWindow<T>(T window) where T:Window
{
Windows.Add(window);
window.Closed += WindowClosed;
window.IsVisibleChanged += WindowIsVisibleChanged;
return window;
}
static void WindowIsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
{
var mainWindow = Application.Current.Windows.OfType<MainWindow>().Single();
mainWindow.Visibility = Equals(e.NewValue, true) ? Visibility.Hidden : Visibility.Visible;
}
static void WindowClosed(object sender, System.EventArgs e)
{
var window = (Window) sender;
window.Closed -= WindowClosed;
window.IsVisibleChanged -= WindowIsVisibleChanged;
Windows.Remove(window);
}
}
How to use:
private void button1_Click(object sender, RoutedEventArgs e)
{
WindowsManager.CreateWindow(new Child1()).Show();
}
private void button2_Click(object sender, RoutedEventArgs e)
{
WindowsManager.CreateWindow(new Child2()).Show();
}
So, when the child window will close, WindowsManager will be notified about this and will update visibility for the main window
UPD1.
added line to unscubscribe from VisibleChanged
You can use several approaches for that.
To easy switch back to main Window: inject a reference of your MainWindow to your SecondWindow (or any other Window you want to display) and in the Closing Event of that Window you set the Visibility of the MainWindow back to Visible.
Have you also considered keeping everything in the same Window but having different Panels that you set Visible and Invisible? That could have the same effect but it's less complicated...
Hope that helps...

About Silverlight UserControl

I Have attached a silver light user control (ex: FirstUserControl.xaml) into my silverlight navigation page project. If I wanna run the application, i need to show the added user control as startup page. How can I set the user control as defualt page in silverlight?
Can any one please give me the solution for this?
You can set it in your App.cs Application_Startup method:
private void Application_Startup(object sender, StartupEventArgs e)
{
// Specify the main application UI
this.RootVisual = new FirstUserControl();
}

Prevent lost focus window on clicking the menu

In my WPF application, my window gets deactivated when selecting a differnt menu from the menubar. I want the current window to be the active window. Is there a way to prevent this from happening?
private void HostWindow_Deactivated(object sender, EventArgs e)
{
//Code for making the window small and move to side using 3d animation
}
HostWindow is the window which holds the usercontrol form at runtime

Resources