I need to get a popup window that is not bound to the main window but will allow me to determine where on the screen should it appear.
Requirements:
I need to be able to decide the size, and location of the new window even if it's on another screen. (I'm already detecting all the screens so this is not an issue)
I need to be able to operate / change values on the main window while the new window stays in place and receives commands from the changing values on the first window and displays them (Text for example)
The new window should be able to display text but also it would be nice if it would be able to receive a background photo/video.
Is it at all possible in MAUI?
I know how to do that in Windows Forms but it looks like Windows Forms ls out of date and it soon will not be supported.
Also MAUI seems to have a nicer appearance out of the box. I really like it but I'm not sure if what I need to do is doable at the moment?
Yes, you can use Multi-window support in MAUI as Jason suggested.
You can call an Action to invoke the method in main window, or communicate with the ViewModel of the main page when you want to receive commands from the changing values on the first window and displays them, see Data binding and MVVM - .NET MAUI | Microsoft Learn
Here's the code snippets below for your reference:
private void OnCounterClicked(object sender, EventArgs e)
{
Window secondWindow = new Window(new NewPage( FirstImage, "First window String to Second", ( string second) =>
{
CounterBtn.Text = second;
})) ;
var displayInfo = DeviceDisplay.Current.MainDisplayInfo;
secondWindow.X = (displayInfo.Width / displayInfo.Density - Window.Width) / 2;
secondWindow.Y = (displayInfo.Height / displayInfo.Density - Window.Height) / 2;
Application.Current.OpenWindow(secondWindow);
}
public NewPage(Image firstImage, string firstTitle, Action<string> firstTitleAction)
{
InitializeComponent();
SecontTitleLabel.Text = firstTitle;//get the text from first window
firstTitleAction("SecondTitle");
}
Related
public void ShowDialog()
{
Window dialogWindow = new Window(new SampleDialog());
Application.Current.OpenWindow(dialogWindow);
// dialogWindow should always be on top of MainPage Window
}
I will be needing a modal dialog to be on top of another modal dialog as well. like how Save Dialogs are on top of lets say the notepad app and the the prompt "Do you want to replace it?" dialog is on top of the save dialog.
I have tried Community toolkit popup. but it can only have 1 popup per window. PushModalAsync is not a desirable outcome as it is still preferred to have separated dialogs.
According to the official docuement about the Windows in .Net Maui, the X and Y property of the Windows can set the position of it. But I tried to use the two properties, they didn't work.
Here is my Code:
Window window = new Window(new NewPage1());
window.MaximumHeight = 200;
window.MaximumWidth = 400;
var width = App.Current.Windows.First().Width;
var height = App.Current.Windows.First().Height;
window.X = width/2;
window.Y = height/2;
You can create a project with .net 7(These propertoes doesn't exist in the .net 6) to test. In addition, you can report it to the maui on the github.
I know this was asked a lot of times probably .. but it is very often answered wrong.
What I want is:
Use a custom icon for specific components/scripts in the Inspector (e.g. Figure 2 and Figure 3) and the ProjectView (e.g. Figure 1)
What I do so far:
For each component/class that shall have the icon I have an accroding Icon file in the folder
Assets/Gizmos/<Path>/<To>/<Namespace>/<ClassName> icon
and in the Import Settigns set TextureType to Editor GUI and Legacy GUI
This is working fine .. and until now the only way how I could achieve that (having in mind the below section What I definitely do NOT want).
But
However, I wondered if there is really no better way having to have a unique Icon file for each script. This makes the project/UnityPackage unnecessarily huge. Also if I rename a class I always have to rename the according icon file as well ... This imply doesn't feel right!
Most Unity build-in Behaviours and Components have a unique icon. But also external Packages coming from the new PackageManager have built-in icons and sometimes a Gizmos folder but it is not following the above naming rule ... so apparently the icon is configured somehow else for them.
Therefore my questions:
Is there any better way to have those icons for scripts/components?
Preferably scripted and reusing ONE single icon file instead of having the same icon in multiple differently named files.
And/or also Where/How are those icons defined for the scripts coming from the PackageManager?
!NOTE! What I definitely do NOT want:
Show the Icon also in the SceneView for all GameObjects having those components attached (e.g. Figure 4). This is caused by either selecting the icon for this script via the Inspector as in Figure 5 (as allways suggested e.g. in this post or here and even by Unity - Assign Icons ) or using OnDrawGizmos or DrawGizmo. This is not happening using the approach I use currently with the Gizmos folder!
Update
Because this was suggested in this answer: I also know that I could do that and turn them off via the Gizmos settings of the SceneView. But imagine I have like 25 different modules and various different icons each. I don't want to have to disable their Gizmos in the SceneView settings one by one on a per project basis! Even the provided script seems like a vast hackaround. Reflection would be the very last resort I would ever take. Also I'ld prefer to not even have those icons appear as possible Gizmos at all instead of disabling them all.
You can set the icon with figure 5 and then turn the gizmos for that icon off from the gizmos drop down.
Edit: Injunction with the step above you could try this script derived from here it uses reflection to find the class responsible for turning off the the gizmos and icons. This would execute any time your scripts recompiled to keep those icons off or if you added any new icons to the autohide icon file. Note: scriptClass will be an empty string for built in components eg.Camera, AudoSource
using UnityEditor;
using System;
using System.Reflection;
public class DisableAllGizmos
{
[UnityEditor.Callbacks.DidReloadScripts]
private static void OnScriptsReloaded()
{
var Annotation = Type.GetType("UnityEditor.Annotation, UnityEditor");
var ClassId = Annotation.GetField("classID");
var ScriptClass = Annotation.GetField("scriptClass");
var Flags = Annotation.GetField("flags");
var IconEnabled = Annotation.GetField("iconEnabled");
Type AnnotationUtility = Type.GetType("UnityEditor.AnnotationUtility, UnityEditor");
var GetAnnotations = AnnotationUtility.GetMethod("GetAnnotations", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);
var SetIconEnabled = AnnotationUtility.GetMethod("SetIconEnabled", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);
Array annotations = (Array)GetAnnotations.Invoke(null, null);
foreach (var a in annotations)
{
int classId = (int)ClassId.GetValue(a);
string scriptClass = (string)ScriptClass.GetValue(a);
int flags = (int)Flags.GetValue(a);
int iconEnabled = (int)IconEnabled.GetValue(a);
// this is done to ignore any built in types
if (string.IsNullOrEmpty(scriptClass))
{
continue;
}
// load a json or text file with class names
const int HasIcon = 1;
bool hasIconFlag = (flags & HasIcon) == HasIcon;
// Added for refrence
//const int HasGizmo = 2;
//bool hasGizmoFlag = (flags & HasGizmo) == HasGizmo;
if (/*Compare class names in file to scriptClass == true*/)
{
if (hasIconFlag && (iconEnabled != 0))
{
UnityEngine.Debug.LogWarning(string.Format("Script:'{0}' is not ment to show its icon in the scene view and will auto hide now. " +
"Icon auto hide is checked on script recompile, if you'd like to change this please remove it from the config",scriptClass));
SetIconEnabled.Invoke(null, new object[] { classId, scriptClass, 0 });
}
}
}
}
}
Shown in the inspector with a gizmo
Hide Icon from gizmos dropdown
Icon still appears in the inspector and in the project view but not in the scene
So I did a bit more research about built in types as well as packages coming from the package manager and the asset store. Anything that is external (packagemanager or assetstore) if it has a custom icon for the script and inspector it will Always have a gizmo in the scene view. As it has its icon set using your figure 5 example, as seen in the screenshots with the debug inspector.
Also if you want to set the icon with a script or hide it ,currently reflection is your only option as these APIs are not publicly accessible.
My Script showing the debug inspector for its script
PixelPerfect package script from the packagemanager in the debug inspector
PixelPerfect Icon showing in the scene
I was hoping to add this as a comment to your original question but not enough rep yet.
I am trying use org.eclipse.jface.window.DefaultToolTip to display some UI components like checkbox,radio buttons placed on composite. When user clicks on a text, the tooltip with pops up to and displays the UI components.
Issue: I want to freeze tool tip once user clicks inside this tooltip. Using toolTip.setHideOnMouseDown(false); I am able to check/un-check the check boxes/radio buttons as long as I am inside the tool tip area. Once mouse pointer exits the tool tip area, the tooltip disappears. How can this be avoided. I am looking for similar behaviour which is available for eclipse tooltips( javadoc, method definition). In Eclipse tooltip, if we click/press f2, tooltip will remain active until we click outside of the tooltip area.
Edit: I also tried to use Eclipse Plugin Spy on tooltip, but no success.
Any thoughts.
What Eclipse does when F2 is pressed is to create a new Shell with exactly the same size and contents as the tooltip and closes the original tooltip.
I use code like the following in an extended tooltip class:
/**
* Switch from tool tip to a normal window.
*/
private void showWindow()
{
if (_control.isDisposed())
return;
final Shell shell = new Shell(_control.getShell(), SWT.CLOSE | SWT.ON_TOP | SWT.RESIZE);
shell.setLayout(new FillLayout());
createBody(shell);
final Point currLoc = _parent.getShell().getLocation();
final Rectangle client = _parent.getClientArea();
final Rectangle bounds = shell.computeTrim(currLoc.x, currLoc.y, client.width, client.height);
shell.setBounds(bounds);
shell.open();
// Hide the tool tip window
hide();
}
_control is the control passed to the constructor.
I have an AutoCompleteTextView control serviced by an 'OnClick' Listener. It extracts a list of items from a database and populates the array adapter attached to the control. When I enter sufficient text to isolate an entry in the adapter list (usually about 2 characters) and I select the identified item, the adapterview's 'OnItemClick' Listener is invoked and I am able to identify the selected item, set the text in the AutoCompleteTextView, and execute its performCompletion() method. When this routine completes, the virtual keyboard remains in place. When I 'Tab' away from the control I receive a NullPointerException!
Any suggestions appreciated ...
PS: this display is generated programmatically.
You can use the snippet below to hide the keyboard.
private static void hideSoftKeyboard (View view) {
InputMethodManager imm = (InputMethodManager)mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getApplicationWindowToken(), 0);
}
I am working on an Eclipse RCP project which has detachable views. I would like to be able to put some text on the window border which surrounds the view once it is detached. Does anyone have any experience with this? Development environment is Eclipse 3.4 on Windows.
THANKS.
I am not sure it is possible through the conventional update triggering a updateTitle():
If you take a look at the code of org.eclipse.ui.internal.DetachedWindow, you will see a disturbing method updateTitle():
private void updateTitle() {
if (activePart != null) {
// Uncomment to set the shell title to match the title of the active part
// String text = activePart.getTitle();
//
// if (!text.equals(s.getText())) {
// s.setText(text);
// }
}
}
All commented!
You cannot. The detached one is a tool window rather than a main window, so it isn't good to have a title on it