Why I can't see my Window on the plug in area? - c#

I'm not able to see my Window in the plug in area. I know that some code must be added in the Integrate section. However i don't know which.
public void Integrate() { }
public void IntegratePresentation() {}
How can I make it visible? Is it really possible?, if not How can I display a window in Petrel?

You should add your window to the system so that Petrel displays it when requested to.
Your window class should be a ToggleWindow:
public class MyWindow : ToggleWindow{
...
}
Add a menu through which you can ask Petrel to create and open your window in the Windows area:
public void IntegratePresentation()
{
WellKnownMenus.Window.AddTool(
new PetrelButtonTool("&My Window",
PetrelImages.Editor,
(sender, e) => PetrelProject
.ToggleWindows
.Add(new MyWindow())));
}
I hope this helps.

Related

TabbedPage - Call method when certain Tab is active

I have a scenario where I want to call a method when the user of the app navigates to a certain tab of the TabbedPage.
Example: If I navigate to tab no. 3 of my TabbedPage, a certain method shall be called.
How do I achieve that?
By default all tabs of the TabbedPage are loaded when I start the app.
I am writing in Xamarin - C#.
Best regards!
There are two sample ways to achieve that.
One is using OnAppearing method inside the needed item of tab page.
For example, the tab no. 3 of TabbedPage is ItemsPage, then its ItemsPage.xaml.cs code as follows:
public partial class ItemsPage : ContentPage
{
public ItemsPage()
{
InitializeComponent();
}
protected override void OnAppearing()
{
base.OnAppearing();
// Call your needed method here
}
}
The another way is using OnCurrentPageChanged methond inside the tabbedpage.xaml.cs.
For example, the code as follows:
public partial class MainPage : TabbedPage
{
public MainPage()
{
InitializeComponent();
}
protected override void OnCurrentPageChanged()
{
base.OnCurrentPageChanged();
if(CurrentPage.Title == "tab no. 3 title")
{
// call your needed method
}
//Console.WriteLine(CurrentPage.Title);
}
}

Syncing data between two Window in WPF

I am developing an application in WPF. I need to load an instance of the Window class (which I call Win1 here) with which a form is filled. Then, when the Submit button is clicked, Win1 closes and only then can a new Win2 window be loaded (another class, also inherited from Window). The problem is that both of them open and I can not synchronize the data obtained from the first Win1 and pass them to the second Win2. I'm just messing up.
Someone can give me a generic idea indicating the tools and the pattern I need to do the above. For the specifications given to me, it is necessary that Win2 appears only after Win1 has finished its work.
Even though the application is more complex than I described it now, I would like to post some code, but I manage to confuse the ideas of who is reading me, so I tell you that at the moment I'm managing the windows inside the constructor of App.cs, while MainWindow.cs corresponds to Win2 and I created a new class to implement Win1.
public partial class App : Application
{
// Params...
public App()
{
Client = LoadNetwork();
User = LoadUser(Client); // Shows Win1
Games = LoadMinigames();
mainWindow = new MainWindow(User, Games);
Application.Current.MainWindow = mainWindow; // On XAML default is Hidden
mainWindow.Show(); // Shows Win2
}
// Other methods...
}
The biggest problem for me is to pass User data to MainWindow and I do not have many ideas on how to deal with this case.
Update
public partial class MainWindow : Window
{
public UserLoading ul;
public UserRegistering ur;
public User.UserProfile User;
private List<Game.Game> Games;
public Label Username;
public MainWindow(User.UserProfile user, List<Game.Game> games)
{
User = new UserProfile();
InitializeComponent();
User = user;
Games = games;
Username.Content = User.Username;
DrawList(Games);
}
//...
}
I realize I have explained myself a bit 'badly rereading my question several times. So I update it trying to be clearer by reporting here my answer to one of the comments.
The UserLoad method is not blocking, because inside it are instantiated classes that inherit Window (other windows for login and registration in other words) then the flow of execution proceeds and instantiates the MainWindow where naturally the argument "user" will result null because the forms have not been filled yet. I realize now that perhaps I had explained myself badly. The call of Win1 is not blocking and I would like it to return only when the user data is ready to be passed as an argument to Win2.
I have done this in the past. here is my solution:
Set Your Launch Window to Win1. Let It launch. Create a Static Method in App.cs to launch Win2. When Win1 is ok to shut down and you want Win2 to open call App.ShowMainWindow(this) from within Win1.
App.cs
public partial class App : Application
{
static internal void ShowWin2(Win1 win1)
{
Win2 win2 = new Win2();
// Copy Win1 stuff to Win2 here
Application.Current.MainWindow = win2;
win2.Show();
}
}
Win1
public partial class Win1 : Window
{
public Win1()
{
InitializeComponent();
}
private void CloseAndLaunchWin2()
{
App.ShowWin2(this);
this.Close();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
CloseAndLaunchWin2();
}
}
As User Nawed mentioned, you should read into MVVM. Syncing can be achieved by using the same model for two different views.
You could do something like this.
var sharedContext = new MyViewModel();
var viewOne = new MyWindow();
var viewTwo = new MyUserControl();
viewOne.DataContext = viewTwo.DataContext = sharedContext;

WPF-Window between desktop and icons (Windows 8.1)

I have used the brilliant article from CodeProject.
http://www.codeproject.com/Articles/856020/Draw-Behind-Desktop-Icons-in-Windows
This project running fine for me on windows 8.1
The example using Forms. Now I'll change the Form
to WPF-Window (using Visualstudio 2015 with .net 4.5.2).
// The WPF-Window for infos behind the icon
public partial class InfoBehindIcon : Window
{
public InfoBehindIcon()
{
InitializeComponent();
// in .xaml: the decoration switched off
}
}
// The MainWindow - class
....
private HInfoBehindIcon.InfoBehindIcon infoBehindIcon = new HInfoBehindIcon.InfoBehindIcon();
public MainWindow()
{
InitializeComponent();
....
iniDesktopHandlerWPF();
... in CodeProject example starting here the Form with
// System.Windows.Forms.Application.Run(InfoBIForm);
... how to start here the WPF-Window behind the Icon?
}
private void iniDesktopHandlerWPF()
{
... Code from CodeProject example
if(dc != IntPtr.Zero)
{
// here I change the Form to WPF-Window
infoBehindIcon.Loaded += infoBehindIcon_EventWPF;
}
}
private void infoBehindIcon_EventWPF(object sender, EventArgs e)
{
infoBehindIcon.Topmost = false;
InfoPanel.HW32.SetParent(new WindowInteropHelper(infoBehindIcon).Handle, workerw);
}
The version using Forms running without problems.
When I am trying this with changes to WPF the second window is starting but
it is not running between desktop and icons.
Is there a way to solve this?
Or it is better way to use furthermore the Form?
(sorry I am a newbee in C#)
The problem was too simple and easy. I solved this
public MainWindow()
{
InitializeComponent();
....
iniDesktopHandlerWPF();
... in CodeProject starting here the Form with
// System.Windows.Forms.Application.Run(InfoBIForm);
... how to start here the WPF-Window behind the Icon?
}
with
public MainWindow()
{
InitializeComponent();
....
iniDesktopHandlerWPF();
... in CodeProject starting here the Form with
// System.Windows.Forms.Application.Run(InfoBIForm);
... how to start here the WPF-Window behind the Icon?
infoBehindIcon.Show();
}
Now it works fine for me. I did not see it...... ;)

WPF maintain window size across multiple windows

I am developing a WPF application (using MVVM) which consists of several windows. All windows have the same dimensions specified and open at the centre of the owner screen. The user may also resize the windows. I now require 2 things.
To maintain the same size across all windows in case the user resizes any of the windows.
To maintain the same position across all windows in case the user drags any of the windows on the screen.
For example, consider the following workflow: MainWindow -> ChildWindow1 -> ChildWindow2. On a button click in the MainWindow, ChildWindow1 opens. On a button click in ChildWindow1, ChildWindow2 opens. The windows open on top of each other, and once you close a window, the previous window would be shown. Suppose the user now resizes ChildWindow2. I want the same to be reflected across MainWindow and ChildWindow1 as well, such that when the user closes ChildWindow2, ChildWindow1 would be of the same size as that of the resized ChildWindow2. This would give users the impression that they're working in the same window.
Also, if the user drags any of the Windows, I want the position of the parent windows to change and correspond to that of the child window.
How can I achieve both these things?
I would create a class where you can subscribe and invoke actions. This class can look something like:
internal class ActionService<T>
{
private static ActionService<T> instance;
private readonly List<ServiceAction<T>> registeredActions;
private ActionService()
{
registeredActions = new List<ServiceAction<T>>();
}
internal static ActionService<T> Instance()
{
return instance ?? (instance = new ActionService<T>());
}
internal void Subscribe(string actionName, Action<T> action)
{
registeredActions.Add(new ServiceAction<T>(actionName, action));
}
internal void Unsubscribe(string actionName)
{
registeredActions.RemoveAll(action => action.ActionName == actionName);
}
internal void Invoke(string actionName, T parameter)
{
foreach (ServiceAction<T> action in registeredActions.Where(action => action.ActionName == actionName).ToArray())
{
action.Action.Invoke(parameter);
}
}
private class ServiceAction<TSub>
{
internal ServiceAction(string actionName, Action<TSub> action)
{
ActionName = actionName;
Action = action;
}
internal string ActionName { get; private set; }
internal Action<TSub> Action { get; private set; }
}
}
In the constructor of each ViewModel you can call something like:
ActionService<Thickness>.Instance.Subscribe("SizeChanged", SizeChaned);
The second parameter is a function so you have to add the following to your ViewModel:
private void SizeChanged(Thickness thickness)
{
// Change the size to the passed value
}
Now if anyone changes the size of any window you can call:
ActionService<Thickness>.Instance.Invoke("SizeChanged", ACTUALSIZE_AS_THICKNESS);
You can use this ActionService anywhere you want to communicate over ViewModel- or Model-Borders.
The way I would approach this is using WPF Behaviors, which allow you to encapsulate UI-specific (i.e. non-View Modelish) behavior.
I don't know your exact requirements here (are these the only windows in the application? Are they always synchronized?) but the general approach would be to create a SynchronizedWindowBehavior which I would attach to the different Windows.
This behavior will access some sort of central WindowSynchronizationService, an event aggregator or singleton service (presumably registered in your DI container) which publishes decoupled events. Each instance of the behavior listens to the attached window's Move and Resize events and publishes an event on the aggregator. The other behavior instances consume this event and resize/move their attached windows accordingly.
Here's a good tutorial, both for defining Blend behaviors, hooking them up to a window, and also (specifically) listening to Window resize events: http://10rem.net/blog/2010/01/09/a-wpf-behavior-for-window-resize-events-in-net-35

MonoTouch.Foundation.MonoTouchException has been thrown Objective-C exception thrown. Name: NSInternalInconsistencyException

I seem to be getting this issue whenever I run my iOS app within Xamarin.
MonoTouch.Foundation.MonoTouchException has been thrown
Objective-C exception thrown. Name: NSInternalInconsistencyException Reason: Could not load NIB in bundle: ’NSBundle ... (loaded)' with name ‘RouteMeViewController'
I am trying to replace a GoogleMapsViewController with a RouteMeViewController using the Objective C library and Binder in an app that I was given to work on. My AppDelegate looks like this:
namespace ExampleApp.iOS
{
[Register ("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate
{
UIWindow window;
RouteMeViewController viewController;
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
window = new UIWindow (UIScreen.MainScreen.Bounds);
viewController = new RouteMeViewController ();
window.RootViewController = viewController;
window.MakeKeyAndVisible ();
return true;
}
}
RouteMeViewController
namespace ExampleApp.iOS
{
public partial class RouteMeViewController : UIViewController
{
RMMapView MapView { get; set; }
public RouteMeViewController () : base ("RouteMeViewController", null)
{
}
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
MapView = new RMMapView(View.Frame, new RMOpenStreetMapSource().Handle);
MapView.AutoresizingMask = UIViewAutoresizing.FlexibleDimensions;
if (UIScreen.MainScreen.Scale > 1.0)
MapView.AdjustTilesForRetinaDisplay = true;
Add (MapView);
}
}
}
Any help or direction is much appreciated, thank you!
It seems you're missing a designer file in the resources of your solution. Even if you programmatically create controls and views, you need a designer file where they need to be drawn in, even if it's just an empty designer file. For IOS, you can use XCode for that. You can create files with the .xib extension. They will be compiled on your device, and the resulting file has the extension .nib. Make sure the target of the .xib file is the correct viewController of your project, else you'll still get the error.
I hope this helps. Good luck!
It is 2023 and this problem still appease for xamarion.IOS
and working fine for xamarion.Android
I'm using the last xamarin forms version 5.0.0.2545
this answer solves my problem
I put a lot of codes after InitializeComponent();
to solve the problem just put MainPage = new MainPage(); directly after InitializeComponent(); in your App.xaml.cs
public App()
{
InitializeComponent();
MainPage = new NavigationPage(new MainPage());
}
The problem now it will directly go to the page without reading the other codes
so to solve this move your code to another page,empty page or splash screen page and put your code in it like
public App()
{
InitializeComponent();
MainPage = new NavigationPage(new MySplashScreenPage());
}

Categories

Resources