In SilkTest is it possible for one window to inherit from another - silktest

I have a window Win1 - it has multiple associated objects and methods.
I want to create window Win2 which is exact replica of Win1 but different in some aspects.
Is it possible to link the two by, say, inheriting one from another.
Something like window
WPFWindow Win2_Win1WithSomeDifferences
inherits Win1
//some more objects
//additional code goes here
Kindly let me know of options.
Using Silktest 13.5.

Yes, it's possible using
winclass Win2_Win1WithSomeDifferences : Win1

Related

How to make some elements of mainWindow common in other views?

I've got standard MainWindow.xaml. Then I added some pages which I wanted to show in the MainWindow. There are some common elements for all views, for example, header text, header image, and the name of logged user. How can I set these elements on the MainWindow that will be visible when another view is shown?
Set the appropriate items in the resources.
Properties that need these values will be able to get them using DynamicResource.
But it will be much better if you implement the Solution in the MVVM pattern.
Then you won't even have such a task (to transfer data between views).

WPF two panel app - reuse or create new instance of panel VM?

I have a WPF application whose main window contains two panels. The layout is pretty standard. The left panel is a a list of objects. The right panel displays information about the object selected in the left panel.
Right now I have the left panel directly in the XAML of the window, although I'm thinking it should be its own UC/View. The right panel is coded as a UC. The ViewModel for the main window has a field that is the VM for the right panel (call it the properties VM). The properties VM encapsulates the data for the selected object from the model.
When a different object is selected in the left panel I see two options:
1) Instantiate a new instance of the properties VM and load the corresponding data from the model
2) Load the corresponding data from the model to the existing properties VM, and issue appropriate change notifications [My current implementation]
Is there an advantage or preferred way of doing things between the two options above? Am I missing a better third option?
* Edit * Maybe a better question is - what are the advantages and disadvantages of the two methods?
Thanks!
You are describing a very standard scenario in the MVVM world. I believe you have a slight architectural issue that when resolved would make this question moot. The 'list' from where you are making your selection should already be a list of view models that wrap the 'object' a.k.a model. The properties view should simply be databound to the selected VM.
Is there an advantage or preferred way of doing things between the two options above?
Not really, but it's probably simpler to just create a new instance and set the data-bound property to this instance instead of trying to re-use and update the state of an existing instance each time the button is clicked.
If you need to cache instances, you could use an IoC container or a custom cache container that resolves the instances for you. You could for example set up the container to always return the same instance of the same class or return a new instance each time depending on your requirements.
But there is "preferred way" really. Your requirements decide what would be the best way to solve your specific issue or use case.

Access windows by name

I am quite new to WPF, coming from the Delphi world. I solved the problem below (albeit painfully) in the Delphi world, and hope there is a more elegant solution in the WPF world.
I need to read in an XML file containing a menu "tree", which has the window names in it as well as the menu prompts, and then be able to "show" a window based on having its name.
For example, a segment of the menu, with two choices, might have XML like this:
<MenuLeaf>
<Header>Product information</Header>
<MenuLine>
<Prompt>Product Master File</Prompt>
<WindowName>Products.xaml</WindowName>
</MenuLine>
<MenuLine>
<Prompt>Inventory Data</Prompt>
<WindowName>Inventory.xaml</WindowName>
</MenuLine>
</MenuLeaf>
So when the user makes the "Inventory Data" choice, I will know that I want to do a "show" of the window Inventory.xaml ..... but I only have the literal string "Inventory.xaml".
I will have hundreds of these forms, and the XML file can vary from time to time - so it's not effective for me to have the standard code of
Dim window as New Inventory
window.Show
for each of the several hundred windows.
What I need is something that does
Dim window as New {go out and find the Inventory file with name Inventory.xaml}
window.Show
I have searched endlessly for this with no luck.
I think the path to solution is to use Reflection, which will allow you to dynamically find/invoke your classes. Say your Namespace is MyNs, then you must have a 'Products' Class within it that correspond to the 'Products.xaml' file. To find it, use MyFoundType = MyNs.GetType("Products")
Then get default (or other if you like) constructor for this type : MyFoundType.GetConstructor(). Then invoke the constructor (with arguments if needed) --> you now have your window as an Object.
Cast it to a window and call its Show method, and you're done.
http://msdn.microsoft.com/en-us/library/y0cd10tb.aspx
http://msdn.microsoft.com/en-us/library/h93ya84h.aspx
http://msdn.microsoft.com/en-us/library/6ycw1y17.aspx
You need to use the XamlReader object, which parses XAML at run-time and creates the object.
var rdr = XmlReader.Create(File.Open("Inventory.xaml"));
var window = XamlReader.Load(rdr) as Window;
window.Show();
The XamlReader.Load will return whatever the actual top-level element in the XAML specifies; if it's a Window you can just .Show it. If it's something else, you'll need a container to place it in. For example, you might have a Window with a Border element in it and do:
var control = XamlReader.Load(rdr) as UserControl;
var window = new MyHostWindow();
window.ContentBorder.Child = control;
If you don't actually know the type of element in your XAML you can usually use FrameworkElement, which is the base class for all the visual elements, though you won't get Window-specific behavior from that.

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!

Rotating windows in WPF

I need to create a WPF application which is maximized and which rotates amongst about 10 different screens. Each screen will take the entire area and show different content.
I already know how to maximize the window with
My question is what is best to put inside that window to achieve what I want?
Ideally I'd be able to have 10 different .xaml files and I just load one after the other to take the entire screen. I'm not sure the best approach for accomplishing this in WPF.
Thank you!
One quick way to do this is to use WPF's built in page navigation. By making your root window a NavigationWindow and each view a class derived from Page (similar to work with to a UserControl or Window) you can just set the NavigationWindow.Source to a relative URI that points to the page you want to show (like a web browser) and simply switch it as needed.
This sounds like a classic MVVM application, which is simply too much to put into detail here. Google MVVM or Model-View-ViewModel, or pick up the book Advanced MVVM by Josh Smith (widely regarded as an expert in such things).
However, this is basically what you are going to have:
One class, the ViewModel, is an abstraction of the data that you need to bind to
Your data Model
A View for each thing you want to show. A View is simply something that holds your UI, be it a DataTemplate or a UserControl. Each View is bound to the ViewModel
The Views are the things that will "rotate" (although rotate in WPF implies animation and/or transformation). How you switch between them is up to you, although it sounds almost like something that would be done with a DispatcherTimer and animation (i.e. like fading between pictures in a slideshow).
This question is really too broad for this forum - you will need to do quite a bit of research on WPF fundamentals before proceeding. Again, MVVM is a good direction to start.
EDIT: Something More Lowbrow, per OP Request
This is probably as simple was you can make it (and still create separate XAML files for each piece of content):
First, create 10 UserControls (XAML files) for the stuff you want to show.
Next, add an instance of each of these user controls to your main window. Set the Visibility of each of these to Collapsed, except the first one to show.
Put a "Next" button on the main window.
In the code-behind, handle the Click event for the Next button. In there, keep track of which UserControl is visible, by name. Set the one that is currently visible to Visibility.Collapsed, and set the next one that is supposed to be visible to Visibility.Visible.
This is certainly an ugly solution, and not very WPF-ish, but it will get the job done.

Resources