Dynamically Change Content by clicking RibbonPane using Prism - wpf

I'm using Microsoft Ribbon and Prism to develop my application. I have in my main window 2 regions: one for the ribbon and the other to inject a view depending on the button clicked in my ribbon.
That works pretty good, but I would like to have the same functionality if I click a specific ribbon tab.
Has anyone done anything like this using Prism?

As you wanted, here is the code using a Button. This code is in the VM of the Ribbon...when the button is clicked the event goes to OnShowConfiguration. This method load a new View in my GeneralContentRegion and also a new RibbonTab.
private void OnShowConfiguration()
{
loadView(PrismViewsNames.GeneralContentMainView, PrismRegionsNames.ContentRegion);
loadView(PrismViewsNames.GeneralRibbonTab, PrismRegionsNames.RibbonMenuRegion);
}
private void loadView(string viewToShow, string regionWhereToShow)
{
var regionManager = (RegionManager)ServiceLocator.Current.GetInstance<IRegionManager>();
var uri = new Uri(viewToShow, UriKind.Relative);
regionManager.RequestNavigate(regionWhereToShow, uri);
}
Myabe that helps you, Ayyappan Subramanian ;)

Related

JavaFX 8 : Combobox with full screen popup

I currently develop a javafx application designed for windows 8 tablet. I use the JMetro theme (a little customized) for the whole application.
I would like the combobox to behave like on Android, opening a full screen popup list.
I think the better and simpler solution would be to create a new skin and to plug it with -fx-skin css ? After that I "only" have to create my popup, react to click event, and setValue of the combobox. I looked at the source code of ComboBoxListViewSkin but I don't see what to change if I extend it...
I there a build-in solution to display a fullscreen combobox popup ?
Any help appreciated. Thank for reading.
The solution was quite simple, but not evident for a beginner.
public class TouchComboBoxListViewSkin<T> extends ComboBoxListViewSkin<T> {
private ComboBox<T> comboBox;
public TouchComboBoxListViewSkin(ComboBox<T> comboBox) {
super(comboBox);
this.comboBox = comboBox;
}
#Override
public void show() {
//TODO use the accessible protected popup to display the list of items
}
}
and a little of css to use this skin :
.combo-box {
-fx-skin: "path.to.TouchComboBoxListViewSkin";
}
Feel free to comment is this is not the right method.

ShowDialog() behind the parent window

I am using ShowDialog() with WindowStyle = WindowStyle.SingleBorderWindow; to open a modal window in my WPF (MVVM) application, but it lets me navigate to parent window using the Windows taskbar (Windows 7).
I've found an answer here: WPF and ShowDialog() but it isn't suitable for me because I don't need an "always on top" tool window.
Thanks in advance
Try setting the Owner property of the dialog. That should work.
Window dialog = new Window();
dialog.Owner = mainWindow;
dialog.ShowDialog();
Edit:
I had a similar problem using this with MVVM. You can solve this by using delegates.
public class MainWindowViewModel
{
public delegate void ShowDialogDelegate(string message);
public ShowDialogDelegate ShowDialogCallback;
public void Action()
{
// here you want to show the dialog
ShowDialogDelegate callback = ShowDialogCallback;
if(callback != null)
{
callback("Message");
}
}
}
public class MainWindow
{
public MainWindow()
{
// initialize the ViewModel
MainWindowViewModel viewModel = new MainWindowViewModel();
viewModel.ShowDialogCallback += ShowDialog;
DataContext = viewModel;
}
private void ShowDialog(string message)
{
// show the dialog
}
}
I had this problem but as the Window was being opened from a view model I didn't have a reference to the current window. To get round it I used this code:
var myWindow = new MyWindowType();
myWindow.Owner = Application.Current.Windows.OfType<Window>().SingleOrDefault(x => x.IsActive);
You can use: myWindow.Owner = Application.Current.MainWindow;
However, this method causes problems if you have three windows open like this:
MainWindow
|
-----> ChildWindow1
|
-----> ChildWindow2
Then setting ChildWindow2.Owner = Application.Current.MainWindow will set the owner of the window to be its grandparent window, not parent window.
When the parent window makes (and shows) the child window, that is where you need to set the owner.
public partial class MainWindow : Window
{
private void openChild()
{
ChildWindow child = new ChildWindow ();
child.Owner = this; // "this" is the parent
child.ShowDialog();
}
}
Aditionally, if you don't want an extra taskbar for all the children... then
<Window x:Class="ChildWindow"
ShowInTaskbar="False" >
</Window>
Much of the reason for the MVVM pattern is so that your interaction logic can be unit tested. For this reason, you should never directly open a window from the ViewModel, or you'll have dialogs popping up in the middle of your unit tests.
Instead, you should raise an event that the View will handle and open a dialog for you. For example, see this article on Interaction Requests: https://msdn.microsoft.com/en-us/library/gg405494(v=pandp.40).aspx#sec12
The problem seems to be related to Window.Owner, and indeed if you judge by previous knowledge that you might have of the Win32 API and WinForms, a missing owner would be the typical cause of such a problem, but as many have pointed out, in the case of WPF that's not it. Microsoft keeps changing things to keep things interesting.
In WPF you can have a dialog with a specific owner and you can still have the dialog appear in the taskbar. Because why not. And that's the default behavior. Because why not. Their rationale is that modal dialogs are not kosher anymore, so you should not be using them; you should be using modeless dialogs, which make sense to show as separate taskbar icons, and in any case the user can then decide whether they want to see different app windows as separate icons, or whether they want to see them grouped.
So, they are trying to enforce this policy with complete disregard to anyone who might want to go against their guidelines and create a modal dialog. So, they force you to explicitly state that you do not want a taskbar icon to appear for your dialog.
To fix this problem, do the following in the constructor of your view class:
ShowInTaskbar = false;
(This may happen right after InitializeComponent();
This is equivalent to Xcalibur37's answer, though the way I figure things, since WPF forces you to have both a .cs file and a .xaml file, you might as well put things that are unlikely to change in the .cs file.
Add "ShowInTaskbar" and set it to false.
Even if this post is a bit old, I hope it is OK that I post my solution.
All the above results are known to me and did not exactly yield the desired result.
I am doing it for the other googlers :)
Lets say f2 is your window that you want to display on top of f1 :
f2.Owner = Window.GetWindow(this);
f2.ShowDialog();
That's it , I promise it will not disappear !
HTH
Guy

How to display a splash screen using Caliburn Micro

I'm using Caliburn Micro v1.3 with WPF. I would like to display a splash screen while my app loads.
I have overriden OnStartup as below but can't see how to close my splash when the base.OnStartup complete
protected override void OnStartup(object sender, System.Windows.StartupEventArgs e)
{
var wm = new WindowManager();
var vm = new StatusReporterViewModel("TEST", "information", null);
try
{
wm.ShowWindow(vm);
base.OnStartup(sender, e);
}
finally
{
vm.TryClose();
}
}
Any ideas?
Cheers
Steve
If you want to use the default WPF splash mechanism then it requires no code.
Add an image file to your WPF .EXE project and then set the properties on the image to "SplashScreen"
If your Splash Screen is an actual customized Window, you can close the SplashScreen in the OnInitialize() Method of your ShellViewModel (or if you dont have a shell, the first view model that gets activated). To get a reference to the SplashScreen in your Shell either inject it or make it a singleton

Creating a mailto: hyperlink in Silverlight Out Of Browser app

Is there a way to create a mailto: hyperlink in a Silverlight 4 OOB app? Thanks!
Edit: based on some of the discussion, an acceptable answer would be a different way than using the HyperlinkButton, or a way to use the HyperlinkButton without having the extra popup in IE.
Ideally it would have been nice of you to post some code, as I have no idea whether the email address is known/determined at design-time or run-time, but nonetheless:
In XAML:
<HyperlinkButton x:Name="mailButton" NavigateUri="mailto:somedude#example.com" TargetName="_blank"></HyperlinkButton>
In C#:
HyperlinkButton hbtn = new HyperlinkButton();
hbtn.Name = "mailButton";
hbtn.TargetName = "_blank";
hbtn.NavigateUri = new Uri("mailto:somedude#example.com");
parent.Controls.Add(hbtn);
In a situation in which you don't know the email address at design time, it's relatively straightforward to assign the value of the NavigateUri property within a method.
I posted a solution to this issue on CodeProject
http://www.codeproject.com/Answers/383879/Silverlight-mailto-HyperlinkButton-always-opens-an#answer2
Essentially, instead of using the default behaviour add a click event and then call javascript location.href. This stops the extra browser window opening.
private void TestLink_Click(object sender, RoutedEventArgs e)
{
//Only run the click event if in browser because this will not work OOB
if (Application.Current.IsRunningOutOfBrowser)
return;
var cmd = String.Format("location.href='mailto:test#test.com?subject=blah&body=something';",
HtmlPage.Window.Eval(cmd);
}

Cannot show up WPF application when setting MainWindow manually and composing application (MEF)

I got my hands om MEF for a week now and I am trying to build up a WPF application that loads imported controls from MEF.
I created a WPF application project and removed the default window and application start up URI. Then I handled the application startup event to compose the application:
public partial class App : Application, IPartImportsSatisfiedNotification
{
{...}
private void App_Startup(object sender, StartupEventArgs e)
{
this.Compose();
}
public void Compose()
{
try
{
globalCatalog.Catalogs.Add(new DirectoryCatalog(extensionsDirectoryPath));
CompositionContainer container = new CompositionContainer(globalCatalog);
container.ComposeParts(this);
}
catch (Exception ex)
{
// Do something
}
}
{...}
}
Actually, when debugging and watching objects after imports are satisfied, everything has hierarchically composed fine like I wanted. But when I try to show up the MainWindow of the application an exception is thrown on MainWindow.Show() call:
"Specified element is already the logical child of another element. Disconnect it first."
Though my code in OnImportsSatisfied method seems fine as it is working when not using MEF mecanism:
public void OnImportsSatisfied()
{
Window mainWindow = new Window();
mainWindow.Content = this.importedControl;
this.MainWindow = mainWindow;
this.MainWindow.Show();
}
I insist on the fact that this works perfectly when not importing controls with MEF. What is surprising is that this code does not work too:
Window mainWindow = new Window();
//mainWindow.Content = this.importedControl;
this.MainWindow = mainWindow;
this.MainWindow.Show();
So I suspect that ComposeParts is doing a bit more than what it says as it is the only member acting on my actual application instance.
Hope someone can help me (Glenn?).
Thanks.
Edit:
I discovered that when I remove the IPartImportsSatisfiedNotification interface from my parts, no exception is thrown and the window shows up. But of course the window is empty as I need this OnImportsSatisfied method to set the DataContext of the window to its associated imported view model.
The sample applications of the WPF Application Framework (WAF) show how to use MEF within a WPF application.
I finally discovered that I was importing my WPF user controls by using the default ImportAttribute constructor, which in fact will make a shared instance of the class if the creation policy is not specified during export. And as many of my controls were implementing the same interface and I was binding them in my views, I was actually trying to add this shared user control instance to different visual elements, which is not permited by WPF (and so the exception).
I marked my imports using the RequiredCreationPolicy set to NonShared and everything got back in order! That was all about learning MEF...

Resources