WPF windows organization techniques - wpf

Im developing some wpf app. Basically i have two types of windows: search windows and insert/edit windows. When i developed win forms apps, i used a trick, called MdiParent. In that way i had ability to put my caled search type windows in a "stack". In orher words if i called 5 different search windows from meniu, they apeared in a component like tab control, one after other.By clicking on that tabs, i could see search results of clicked tab window. The trick as i said was MdiParent technique, like:
private ProductDiscount frmProductDiscount = null;
private void ProductDiscountToolStripMenuItem_Click(object sender, EventArgs e)
{
if ((frmProductDiscount == null) || (!frmProductDiscount.Visible))
{
frmProductDiscount = new ProductDiscount();
frmProductDiscount.MdiParent = this;
frmProductDiscount.Show();
}
else
{
frmProductDiscount.Activate();
}
}
So does anyone can me suggest a good way to implement such a window organization technique in WPF and put some links or examples..?That would be a big help for me.

There is no equivalent of Form.MDIParent in WPF and MDI does not support the idea of an MDI layout. You can set a Windows Owner to another window. This will minimise the child when the parent is minimised.
For an example of MDI style functionality have a look at this thread link text
where Marlon Grech has written something similar to what I believe you are trying to do.

We developped similar application, as WPF doesnt have any default MDI framework but since its completely customizable, what you can do is, you can create User Controls of your "Window" instead of Window type and you can use inside a TabControl and you can customize TabControl to have close buttons etc. Windows in Tabs as they appear in Visual Studio, IE etc, they work good for this type of scenario when you dont want to block user input on modal dialog.

Related

fit child form inside a certain dock panel in the parent form

( using wpf ) Can some one tell me How to open child window from parent window and after opening it should be fit inside a dock panel in the Parent Window !!?
the Code is
private void Button_Click_1(object sender, RoutedEventArgs e)
{
chiledForm cw = new chiledForm ();
cw.ShowInTaskbar = false;
cw.Owner = Application.Current.MainWindow;
cw.Show();
}
Thanks
WPF has indeed no built-in support for Multiple Document Interface (MDI) but you could take a look at the following open source project:
WPF Multiple Document Interface (MDI): https://wpfmdi.codeplex.com/
It is a library to add the traditional Windows Forms Multiple Document Interface (MDI) features to WPF.
What you are trying to achieve here is MDI which is a functionality available in WinForms.
WPF does not support that functionality instead you can use AvalonDock
which offers similiar functionality.
I haven't used that personally so I can't guarantee it will fit your requirements.

wpf dual monitor application?

I'm very new to WPF. I want to create a dual monitor/projector application. What I want to do is have the "presenters screen" on one monitor and another panel on the secondary monitor, similar to how powerpoint works. I'm struggling to wrap my mind around the panels and XAML. So what I'm after is user clicks on a button on screen1 and information gets updated on screen2.
I'm using this code:
this.Width = System.Windows.SystemParameters.VirtualScreenWidth;
this.Height = System.Windows.SystemParameters.VirtualScreenHeight;
this.Top = 0;
this.Left = 0;
to set the width and height of the screen.
Edit:
The later goal is to cause screen2 to retrieve items out of a database based on the selection on screen1
Question: tutorials, places to go, nudges on how to update monitor2 from a button on monitor1
Short Answer
Create a view model that shared between two views; make one of the views the master (makes the changes) and the other pure presentation. The views are new windows. Initially do not be concerned with the window position (we'll get to that later) just get the shared viewmodel working.
Tip: research the MVVM pattern. Google has a lot of articles on the subject.
Long Answer
After you have researched MVVM and created a few example applications (from scatch or using a framework), below are few additional features you want implement to create the "powerpoint-like" application.
Fullscreen Mode
At the very least you will want the presentation window to be full screen. To achieve this, you set the WindowStyle to None and AllowsTransparency to True.
If you want to make the second window also fullscreen you may need to do some Win32 overrides to get the window to maximize properly without covering the taskbar (post a comment if you want to know how to do this).
Detect Multiple Monitors
Get the size and position of the monitors using Win32 Interop commands. There will be plenty of articles on the Internet that will help you with this (or post another StackoverFlow question).
This would be a neatâ„¢ feature as it will position the two windows correctly (use the secondary screen as the presentation).
That is all that I can think of now, post-back if you any questions on MVVM or any of the additional points above.
1) You should have 2 Windows, the way this looks I'd make monitor2 a child window of monitor1 (after all, it is a child ;)
What i mean by that, is that StartupUri in App.xaml should point to monitor1, and in monitor1's constructor, you should create an instance of monitor2 (which would be a singleton if i were to do it).
2) To maximize a window on the second screen:
Subscribe to the Loaded event of the window (in code-behind), and set
private void Window_Loaded(object sender, RoutedEventArgs e) {
WindowState = WindowState.Maximized;
}
More info (and source): here
3) As to how to make monitor2 react when you set something in monitor1, make monitor1 and monitor2 bind to the same ViewModel, only they show different stuff.
Hope this helps!

Key strokes in wpf window hosted in MFC ActiveX running in Internet Explorer

We have an MFC ActiveX control created in Visual Studio 2008 with CLR support which creates a WPF grid and shows a WPF window within that grid.
This ActiveX is hosted within Internet Explorer and it shows up and works nicely except that the tab key, backspace, function keys etc. does not work since they are handeled by IE instead of the WPF window. Regular characters works nicely. This is a known feature and previously when we used to have MFC based dialogs within this ActiveX we used this: http://support.microsoft.com/kb/187988. By just using this code directly the
AfxGetApp()->PreTranslateMessage((LPMSG)lParam)
statement will return FALSE, so I'm not able to get the key stroke to be handled by the WPF window. I beleive I need to ask the WPF application this instead of the CWinApp, but I'm not sure how and if this can be done. Does anyone have enough understanding of what's going on here to get this to work?
Using XBAP instead of ActiveX is not an option as this is run in an intranet application which needs more access than the sandbox can give us.
I hope this is enough information.
With best regards
Svein Dybvik
We have hosted a WPF user control inside an MFC modeless dialog. In order to get some keyboard stuff working correctly, we had to modify the dialogs PreTranslateMessage() function.
Basically, what we did was to check to see if the message was for the WPF window. If it was, we immediately call TranslateMessage/DispatchMessage and then return TRUE from PreTranslateMessage.
Our WPF control fills the entire dialog, so you'd have to have your own conditional check where we have the IsChild test.
BOOL CHostDlg::PreTranslateMessage(MSG* pMsg)
{
// normal PreTranslateMessage() causes the edit fields not to work
if (::IsChild(GetSafeHwnd(), pMsg->hwnd))
{
TranslateMessage(pMsg);
DispatchMessage(pMsg);
return TRUE;
}
return baseclass::PreTranslateMessage(pMsg);
}
Some edit:
BOOL CHostDlg::PreTranslateMessage(MSG* pMsg)
{
// normal PreTranslateMessage() causes the edit fields not to work
if (::IsChild(GetSafeHwnd(), pMsg->hwnd))
{
TranslateMessage(pMsg);
DispatchMessage(pMsg);
pMsg->hwnd = GetSafeHwnd(); // redirect to parent
}
return baseclass::PreTranslateMessage(pMsg);
}

WPF search windows - like tabPages in tab control

I have idea to implement my wpf windows like TabPages in tab control. It is possible to do that dynamically in c# code.
In Example i have Menu in main window. Some Menu items calls search type windows. Is it possible to do such a thing in C# code (SomeMenuItem_Click): this code adds new tab in tabControl of main window.
If there are no search windows called -there is no tab's shown, if there are many search windows called - there are many tab's.
So how do I code this?
And whats the technique with the windows? I suppose that my search type windows must be implemented like some UserControls. I think its no a good idea to implement that like simple wpf windows. I have tried to do that by using Marlon grech "Blend like UIs using DOCKY", find at:
http://marlongrech.wordpress.com/2008/01/29/create-blend-like-uis-using-docky/
But I failed, dont find the way how to add controlls in code dynamically, not in xaml.
I would appreciate code examples to illustrate how to achieve this.
Is it possible to do such a thing in C# code (SomeMenuItem_Click): this code adds new tab in tabControl of main window.
Yes. The basic pattern is:
TabItem newItem = new TabItem();
tabControl.Items.Add(newItem);
You'll obviously need to set the relevant properties of your tab item (such as the Header and Style) but that should get you started.
You'll then need to create any controls you want to show and add them to the tab item itself (or more correctly - a container within the tab item).

Using SetWindowTheme() on controls in WindowsFormsHost in WPF?

I have an application I'm developing which closely mirrors Windows 7's Device Stage. In Device Stage, beneath the main banner there is a ListView containing actions embodied as ListViewItems.
In my WPF application, I used WindowsFormsHost to host a WinForms ListView so that I could use SetWindowTheme() on it and apply Windows Vista/7 styling to it.
This, however, does not work and doesn't achieve the same effect it does when used in Windows Forms.
How can I achieve the Windows 7 look on a ListView in WPF? I'm not looking to create a custom style then apply it because frankly that's too much of a pain in the ass to continue using WPF for this app.
Thanks! :)
Just add the following lines:
[DllImport("uxtheme.dll", CharSet = CharSet.Unicode)]
public static extern int SetWindowTheme(IntPtr hWnd, String pszSubAppName, String pszSubIdList);
.ctor
{
System.Windows.Forms.Integration.WindowsFormsHost.EnableWindowsFormsInterop();
System.Windows.Forms.Application.EnableVisualStyles();
SetWindowTheme(MyControl.Handle, "Explorer", null);
}
Apparently after digging around, the only answer does indeed appear to be creating a custom-designed control in WPF.

Resources