I am launching a window using HtmlPage.Window.Navigate(Uri, "_blank"); from a Grid row using a context menu for some custom editing specific to a page referred by the row. I am using telerik-grid in silver-light. I want to refresh the grid when user closes that window. How can i do this?
Please share some idea on, Is this possible? or where to look for start to tackle this?
UPDATE: I am using Silver-light MVVM model. The child window I am opening from silver-light is the the web browser, I would actually need a technique where I can have the grid in the silver light application to get refreshed when I close the web browser. Additionally i am using RIA service to expose the methods for the web browser.
Expose a method in your Silverlight app that is accessible from Javascript.
namespace SilverlightApplication
{
public partial class Page : UserControl
{
public Page()
{
InitializeComponent();
HtmlPage.RegisterScriptableObject("Page", this);
}
[ScriptableMember]
public void UpdateDataGrid()
{
myDataGridItemsReload(); // your routine
}
}
}
Then in the newly opened window, you can execute a method on the Silverlight instance
<script>
window.onunload = refreshParentGrid;
function refreshParentGrid() {
var hostDiv = window.opener.document.getElementById("silverlightControlHost");
var control = hostDiv.children[0];
control.Content.Page.UpdateDataGrid();
}
</script>
Related
Brand new to AutoCAD plugin development. I'm trying to create a plugin that loads as an entire main menu option inside of AutoCAD (let's call this menu the "Fizzbuzz" menu, and when the user selects one of the menu items (say, Fizzbuzz >> Foobar) I want a simple dialog/window to show up on screen in the top-left corner of AutoCAD.
I'm trying to figure out where the presentation/layout logic for this dialog/popup window needs to go (what file does it live in and how do I create/edit it?), and just as importantly: where the event-driven GUI logic needs to go (again: what file do I edit and in what language?). By "GUI logic" I mean: let's say there's a checkbox or button inside my dialog...when the user clicks/interacts with these UI components, I need custom logic to execute.
Any idea what files house this type of presentation/GUI logic for new AutoCAD plugins and how I create/edit them? Thanks in advance!
I have added a palette hosting a winform control this way:
using System.Windows.Forms;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Windows;
namespace AMU.AutoCAD.BlockTool
{
public class MyPalette : IExtensionApplication
{
private PaletteSet palette;
private Control paletteControl;
public void Initialize()
{
//This is called when AutoCAD loads your assembly
this.palette = new PaletteSet("Name")
{
TitleBarLocation = PaletteSetTitleBarLocation.Left,
Style = PaletteSetStyles.Snappable //Your Styles
};
this.paletteControl = new Control(); //Instance of your Control that will be visible in AutoCAD
this.palette.Add("HEADER", this.paletteControl);
this.palette.Visible = true;
}
public void Terminate()
{
//cleanup
this.palette.Dispose();
this.paletteControl.Dispose();
}
}
}
By providing a class implementing the IExtensionApplication you can execute custom code on loading a dll, without explicitly call a method. You now can create a so called PaletteSet and add a Winform or WPF Control to it.
My Prism 6 WPF MVVM modular application (with Unity DI) has to display modal login window atop Shell, after it has loaded, to ask user about username and password. (This is the demand of production target on my job.) I've read post at http://compositewpf.codeplex.com/discussions/58292 but this post is describing how to display login window before displaying of Shell but my application must display login window atop Shell (so Shell must be displayed on a background). Moreover, this post describes how to do it in Prism 2 but I use Prism 6 and I want to use Prism Window(WPF) as a view for login window. Below is my application structure:
Where 'AuthrizationView.xaml is Prism Window(WPF) that is login window that has AuthrizationViewModel view model in ViewModels folder and AuthrizationModel model in Models folder in 'Authorization' project in solution. And MainWindow.xaml is Shell that has MainWindowViewModel view model in ViewModels folder in 'FlowmeterConfiguration' project in solution. So I have the following questions here:
How to display login modal window atop Shell?
How to close login window when user click 'Login' button in this window after he or she has typed username and password in appropriate boxes?
How to close login window when user click 'Cancel' button in this window if he or she doesn't want to login?
Can login window be activated again and again to change the user by clicking on appropriate menu item in Shell?
Can I add keyboard shortcut support for such menu item?
Your help will be appreciated highly.
You should use the InteractionRequest<T> type to trigger an interaction request in XAML which will show a new modal window. After the user enters the data, it will transport it back to the caller.
Check out my previous answer on this topic found here.
If you need to transport input of the Interaction Request back to the calling view, your need to implement a class that inherits from IConfirmation or Confirmation and define its fields, then use it in the callback.
From my other answers example, that would be
public class LoginConfirmation : Confirmation
{
public string Login { get; set; }
public SecureString SecurePassword { get; set; }
}
public InteractionRequest<LoginConfirmation> LoginConfirmationRequest
{ get; private set; }
this.LoginConfirmationRequest = new InteractionRequest<LoginConfirmation>();
then call the request via
this.LoginConfirmationRequest.Raise(
new LoginConfirmation { Title = "Please enter your login" }, OnLoginResponse);
protected virtual void OnLoginResponse(LoginConfirmation context)
{
if(!context.Confirmed)
{
// user canceled
return;
}
// user confirmed login
this.myAuthorizationService.Login(context.Login, context.SecurePassword);
}
The viewmodel of your login window needs to implement IInteractionRequestAware to be able to pass data back to your shell.
public class LoginViewModel : BindableBase, IInteractionRequestAware
{
public Action FinishInteraction { get; set; }
private INotification notification;
public INotification Notification
{
get { return this.notification; }
set { SetProperty(ref notification, value); }
}
}
Where the LoginConfirmation will be in the notification property and you can set it's values there and after calling FinishInteraction() the window will be closed and returned back to your shell or wherever you called it
The trick is in this situation is to have your 'popup' UI sat in a grid with a higher Z-order than the shell content UI, and have its visibility set to 'Hidden'. Then when you need the user to login you can set the Visibility to 'Visible' and it will appear on top of your UI in the shell.
For the Modal behavior, you need to use DispatcherFrame to create a nested message pump, which will block your main UI while the newly-visible login UI handles the users input.
There is a great article and sample code here
Modal Controls Via DispatcherFrame
I have windows form application in C#.
I have class library for WPF user control. And I am using that in Windows Form App using Element Host. Now in WPF User control i need to show one message using MessageBox. it's working but displayed modeless on Main Form of Windows Form Application. I want to Show this Message box as model.
Any help please.
Edits:
let me Explain by example:
I have “WindowsFormApp1”
Another is “WPFUserCtrlLib” which is class library. And it has UserControl named as “WPFUserCtrl” so I have “WPFUserCtrl.xaml” and “WPFUserCtrl.xaml.cs” Files.
In WindowsFormApp1 I have MainForm named “Form1”. In Form1 I am using “WPFUserCtrl” using Element Host.
Now there is some logic resides in “WPFUserCtrl.xaml.cs” say
String ErrorMsg=“Error There”;
if(condition)
{
//Do Task
}
else
{
MessageBox.Show(ErrorMsg);
}
So here I need to show ErrorMsg. When this MessageBox is displayed, it is modeless as I am able to access controls on “Form1” like menus, buttons and all.
Did you set the owner of the WPF window to the winforms window?
According to this link that is necessary in order to make the modal dialog work within winforms.
var window = new WpfWindow();
var helper = new WindowInteropHelper(window);
helper.Owner = this.Handle;
window.ShowDialog();
I have tried lot. Couldn't get solution so posted question here and continued to try again with diff approach. And Now I found the solution.
Solution is: use Dispatcher.Invoke
if(condition)
{
//Do Task
}
else
{
Dispatcher.Invoke(new Action(() => {
MessageBox.Show(ErrorMsg);
})
);
}
Now my MessageBox is model.
I want to show a popup when someone click on a button, the button is in a listview which is load from a webservice, how can I send a message to the view to call the AlertDialog function ?
I was maybe not very clear I paste my code bellow to see what I tried :
In my viewmodel :
public void editPost(Post item)
{
PostToEdit = item;
// Call the popup function
}
In my view :
public Dialog showEditPopup()
{
var customView = LayoutInflater.Inflate(Resource.Layout.EditDialog, null);
var builder = new AlertDialog.Builder(this);
builder.SetView(customView);
builder.SetPositiveButton("Save", SaveClicked);
builder.SetNegativeButton("Cancel", CancelClicked);
return builder.Create();
}
I tried to create an onclick function to initialize my AlertDialog in the View
var editButton = FindViewById<Button>(Resource.Id.editButton);
editButton.Click += delegate { ShowDialog(EditDialog); };
But the application crash because the posts aren't load at the time of the oncreate so the editButton is null and the event click cannot be set, so I want to create the popup in the viewmodel.
One way you can go about this is to set (from the view) an Action or Func callback on the VM, which will show the dialog, and it can be initiated from the VM.
The other option would be to have an interface defined by the VM which the View will implement (for example IViewInteraction which has a method like ShowDialog(string text).
I would suggest the first approach.
Probably there's going to be more than one place where you will need to show an alert dialog in your app.
In MvvmCross there's a plugin to show dialogs in all platforms. You implement calling it from view-model and it will work on all platforms.
https://github.com/brianchance/MvvmCross-UserInteraction
I suggest you add it by NuGet
I'm new to Caliburn.Micro and I'm wondering what is the best way to handle user Login/Logout cycles in my application. I saw some suggestions online to implement this using an empty Shell-View which switches between the LoginView and the main application view, each with a custom ViewModel of course.
I don't really like this solution, because for me these are 2 separate windows with very different properties (Title, Icon, Size) and it seems an unclean solution two change one window to look like the other. Another problem is, that the Login Window comes from an utility library which I don't control and which doesn't use Caliburn.Micro, it's a plain old Window which gives me an event when the user clicks "Login".
I also saw suggestions to display this Dialog in the Bootstrapper startup method, but the problem I see with that is that the user can choose to "Logout" of the application which should display the Login dialog again. It seems wrong to me to handle the switching between the Views in the Bootstrapper.
What I would like is to have some sort of ApplicationViewModel or ApplicationController which works like a Caliburn Conductor, but instead of switching between Views inside a Window, it should switch between the LoginWindow and the MainWindow and should also handle Closing of the whole application (which also requires a Logout). On Activation it would show the LoginWindow, handle the Login event and then switch to the Main Window (Shell). If the user chooses to "LogOut", the event should bubble up to the ApplicationViewModel/Controller again which would deactivate/close the MainWindow, perform the Logout and then show the LoginDialog again. Similar a Close event would do the Logout, but then Shutdown the whole application.
So my questions are:
What do you think about this solution and do you have another/better one?
How do I implement this? ;-)
Thanks a lot!
I think the solution to your problem is fairly easy.
In a nutshell you are creating one ViewModel as Shell which is represented with a Login Window when the application starts. If the user logs in successfully this window closes and the same instance of the viewModel is displayed in a Content Window. If the user is doing a logout, the Login Window is shown again.
First of all create an interface IShell which exposes two delegates LoginSuccessful and Logout
public interface IShell
{
Action LoginSuccessful { get; set; }
Action Logout { get; set; }
}
Next create a class ShellViewModel which implements IShell
public class ShellViewModel : Screen, IShell
{
public ShellViewModel()
{
LoginSuccessful = delegate { };
Logout = delegate { };
}
public Action LoginSuccessful { get; set; }
public Action Logout { get; set; }
public void DoLogin()
{
LoginSuccessful();
}
public void DoLogout()
{
Logout();
}
}
The methods DoLogin and DoLogout are Actions which can be bound to a Button or whatever control appropriate for you.
Next step is to override the OnStartupMethod in your Bootstrapper. This premises that you have an instance of the WindowManager and ShellViewModel exported by an IoC Framework of your choice.
protected override void OnStartup(object sender, StartupEventArgs e)
{
var windowManager = IoC.Get<IWindowManager>();
var viewModel = IoC.Get<IShell>();
viewModel.LoginSuccessful =
() => GuardCloseAndReopen("Content");
viewModel.Logout =
() => GuardCloseAndReopen("Login");
windowManager.ShowWindow(viewModel, "Login");
}
private void GuardCloseAndReopen(string shellViewMode)
{
var windowManager = IoC.Get<IWindowManager>();
var shellScreen = IoC.Get<IShell>() as Screen;
Application.ShutdownMode = ShutdownMode.OnExplicitShutdown;
shellScreen.TryClose();
Application.ShutdownMode = ShutdownMode.OnLastWindowClose;
windowManager.ShowWindow(shellScreen, shellViewMode);
}
The trick to this is: If the DoLogout method is called, the current window gets closed by calling TryClose on the ShellViewModel. At the same time you prevent the application from being shutdown by setting the Application.ShutdownMode to OnExplicitShutdown. Then using the windowmanager, you create another window in Login Mode by passing "Login" as Context information to the windowManager. This is actually the same ViewModel, however, with a different visual representation.
For Logout you are doing the same thing just around.
To get this working using Caliburn Conventions, you need a special project structure as seen here (and explained there):
Now I challenge you to take this code and create a little sample application. Create a Login View (which does Login with a Button or whatever) and create a Content View with a Logout Button using the LoginSuccessful/ Logout Methods.
This will solve your issue with a minimum of Code and classes. Hope this will be helpful to you.
I've had a go at creating something that basically works but probably needs a bit more work to be really usable. The fully comments and source can be found on this post Caliburn.Micro Login Window sample on my website.
I used the IEventAggregator of Caliburn.Micro to control the transition between the two windows. You get this code to open the login screen:
public void Handle(LoginEvent message)
{
LoginWindow loginWindow = new LoginWindow();
loginWindow.Login += new EventHandler<LoginEventArgs>(this.LoginWindow_Login);
loginWindow.Cancel += new EventHandler(LoginWindow_Cancel);
loginWindow.ShowDialog();
}
this same source is used for both the first time the app opens and when the Logout event is published. the Logout event looks like this:
public void Handle(LogoutEvent message)
{
Application.Current.ShutdownMode = ShutdownMode.OnExplicitShutdown;
message.Source.TryClose();
Application.Current.ShutdownMode = ShutdownMode.OnLastWindowClose;
this.events.Publish(new LoginEvent());
}
When a login is successful it uses this code to open the main window which is based on a ViewModel:
ContentViewModel viewModel;
viewModel = IoC.Get<ContentViewModel>();
viewModel.Username = e.Username;
this.windowManager.ShowWindow(viewModel);