I'm writing a Windows Phone Mango app. I have a hyperlink that contains email addresses. I want it to show a message box on tap:
Hyperlink href = new Hyperlink();
href.Click += (s, r) =>
{
MessageBox.Show("href clicked");
};
// add href to RichTextBox
When I click on the hyperlink in the emulator, nothing happens. The click += line is hit in a debugger, but the new EmailComposeTask() line isn't.
What am I doing wrong? Is Click not the event I want?
Update: I switched EmailComposeTask to MessageBox to verify that this issue isn't related to the email compose task not running on the emulator. I've reproduced this issue on my device.
The following code works:
GestureService.GetGestureListener(href); // adding this makes it work
href.Click += (s, r) =>
{
MessageBox.Show("href clicked");
new EmailComposeTask() { To = entireLink.Value }.Show();
};
href.Inlines.Add(new Run() { Text = entireLink.Value });
GetGestureListener creates a gesture listener if it doesn't already exist.
You should use HyperlinkButton Class, Hyperlink is a class used with rich text document rendering.
Following code is runs on device. text is RichTextBox object.
var linkText = new Run() { Text = "Link text" };
var link = new Hyperlink();
link.Inlines.Add(linkText);
link.Click += (o, e) =>
{
MessageBox.Show("Link clicked");
};
var paragraph = new Paragraph();
paragraph.Inlines.Add(link);
text.Blocks.Add(paragraph);
Related
I want to create a Qooxdoo application that consists of a Desktop with multiple Windows. The Desktop (and not each Window) also has a (common) ToolBar.
Now I want to have a command to "save" the document of the active window. This command can be triggered by the keyboard shortcut "Ctrl+S" as well as a button on the toolbar.
To handle the "Ctrl+S" to reach the currently active window the qx.ui.command.GroupManager (as described by https://qooxdoo.org/documentation/v7.5/#/desktop/gui/interaction?id=working-with-commands and https://qooxdoo.org/qxl.demobrowser/#ui~CommandGroupManager.html) is supposed to be the best solution. And I could easily implement that in my code.
But now I'm struggling to make the toolbar save button also call the save command of the currently active window as I don't know how to bind it correctly to the GroupManager.
An example code to get started in the playground https://qooxdoo.org/qxl.playground/:
// NOTE: run this script only once. Before running it again you need to reload
// the page as it seems that the commands are accumulation and not reset.
// I guess that this is a bug in the Playground
const root = this.getRoot();
qx.Class.define('test.Application',
{
extend : qx.application.Standalone,
members: {
main: function() {
const layout = new qx.ui.layout.VBox(5);
const container = new qx.ui.container.Composite(layout);
root.add(container, {edge: 0});
const windowManager = new qx.ui.window.Manager();
const desktop = new qx.ui.window.Desktop(windowManager);
this._manager = new qx.ui.command.GroupManager();
const menuBar = new qx.ui.menubar.MenuBar();
let menu = new qx.ui.menu.Menu();
///////////////////////////
// TODO: Call _doSave() of the active window!
let saveMenuButton = new qx.ui.menu.Button('Save','#MaterialIcons/save/16');
///////////////////////////
menu.add(saveMenuButton);
var fileMenu = new qx.ui.menubar.Button('File', null, menu);
menuBar.add(fileMenu);
const toolBar = new qx.ui.toolbar.ToolBar();
///////////////////////////
// TODO: Call _doSave() of the active window!
let saveToolBarButton = new qx.ui.toolbar.Button('Save','#MaterialIcons/save/16');
///////////////////////////
toolBar.add(saveToolBarButton);
container.add(menuBar,{flex:0});
container.add(toolBar,{flex:0});
container.add(desktop,{flex:1});
this._foo1 = new test.Window('foo1', this);
desktop.add(this._foo1);
this._foo1.open();
this._foo1.moveTo(100,20);
this._foo2 = new test.Window('foo2', this);
desktop.add(this._foo2);
this._foo2.open();
this._foo2.moveTo(200,100);
this._foo3 = new test.Window('foo3', this);
desktop.add(this._foo3);
this._foo3.open();
this._foo3.moveTo(300,180);
},
getGroupManager() {
return this._manager;
}
}
});
qx.Class.define('test.Window', {
extend: qx.ui.window.Window,
construct(windowName, controller) {
this.base(arguments, windowName);
this._name = windowName;
let commandGroup = new qx.ui.command.Group();
const cmd = new qx.ui.command.Command("Ctrl+S");
cmd.addListener('execute', this._doSave, this);
commandGroup.add('save', cmd);
controller.getGroupManager().add(commandGroup);
this.addListener('changeActive', () => {
if (this.isActive()) {
controller.getGroupManager().setActive(commandGroup);
}
}, this);
},
members: {
_doSave() {
alert("save " + this._name);
}
}
});
a = new test.Application();
How should the saveMenuButton.setCommand() and saveToolBarButton.setCommand() should look like to always call the command of the active window?
You can control a current active window via Desktop class:
let saveToolBarButton = new qx.ui.toolbar.Button('Save');
saveToolBarButton.addListener("click", function(){
desktop.getActiveWindow()._doSave();
}, this);
Would be great for your solution imo is to create a separate command and add this command to buttons:
const saveActiveWindowCommand = new qx.ui.command.Command();
saveActiveWindowCommand.addListener("execute", function(){
desktop.getActiveWindow()._doSave();
}, this);
let saveMenuButton = new qx.ui.menu.Button('Save');
saveMenuButton.setCommand(saveActiveWindowCommand);
let saveToolBarButton = new qx.ui.toolbar.Button('Save');
saveToolBarButton.setCommand(saveActiveWindowCommand);
EDIT:
You could set commands dynamically for "Main Panel" menu buttons. Because there is only one instance of command pressing "Ctrl+S" will trigger only one command but maybe you would like that main bar save buttons have extra logic.
You have in application class next method which will be called from window class when changeActive event happens.
setSaveCommand(command){
this.saveMenuButton.setCommand(command);
this.saveToolBarButton.setCommand(command);
},
and in your Window class:
if (this.isActive()) {
controller.setSaveCommand(cmd);
controller.getGroupManager().setActive(commandGroup);
}
The removeCommand and removeAllCommand is not working. If i put it in a button action listener removeCommand(command) works but removeAllcommand() is not working?
Is it a bug? Please check it out. Thankyou
Command d = new Command("back") {
#Override
public void actionPerformed(ActionEvent evt) {
}
};
f.setBackCommand(d);
f.getToolbar().addCommandToLeftBar(d);
//Either of these two doesnt remove above back command...
f.removeAllCommands();
f.removeCommand(d);
If i put it in action listener, one of them work
Button add = new Button("remove");
add.addActionListener((e) -> {
f.removeCommand(d);// it removes back command
f.removeAllCommands(); // it doesnt work
});
Try to revalidate the Form
Button add = new Button("remove");
add.addActionListener((e) -> {
f.removeAllCommands();
f.revalidate();
});
I would like to know how to create Messages Dialogs in Mahapps. All the examples i've found were about clicking a button, but i need to create the Message from inside code (in the middle of a Try in a static async i.e.).
So... this is the code behind the MainWindow (From the GIT examples)
public async void ShowMessageDialog(object sender, RoutedEventArgs e)
{
// This demo runs on .Net 4.0, but we're using the Microsoft.Bcl.Async package so we have async/await support
// The package is only used by the demo and not a dependency of the library!
var mySettings = new MetroDialogSettings()
{
AffirmativeButtonText = "Hi",
NegativeButtonText = "Go away!",
FirstAuxiliaryButtonText = "Cancel",
ColorScheme = MetroDialogOptions.ColorScheme
};
MessageDialogResult result = await this.ShowMessageAsync("Hello!", "Welcome to the world of metro!",
MessageDialogStyle.AffirmativeAndNegativeAndSingleAuxiliary, mySettings);
if (result != MessageDialogResult.FirstAuxiliary)
await this.ShowMessageAsync("Result", "You said: " + (result == MessageDialogResult.Affirmative ? mySettings.AffirmativeButtonText : mySettings.NegativeButtonText +
Environment.NewLine + Environment.NewLine + "This dialog will follow the Use Accent setting."));
}
How i could i call ShowMessageDialog from any other ViewModels and show the Dialog over that MainWindow?
Thanks!
You can get the ActiveWindow Like so :
var metroWindow = Application.Current.Windows.OfType<Window>()
.SingleOrDefault(x => x.IsActive) as MetroWindow;
I would suggest to make a MessageService that retrive the Active Window and manage all the messages of your application. Furthermore, you should Implement a interface (IMessageService) if you want the ability to Unit Test your code.
I have a ModernTab control, to which I'm dynamically adding a Link:
InstallationTab.Links.Add(new Link { DisplayName = "Review Configuration", Source = new Uri("/Views/InstallationProgress.xaml", UriKind.Relative) });
I'd like InstallationProgress.xaml to load in the top frame instead of the current content frame.
How can I do this?
I answered my own question, in case anyone else finds themselves here:
This is just one example of "hijacking" the click on the ModernTab. Here, you can force the content to load in the top frame, for example:
Handle the SelectedSourceChanged event of the ModernTab:
MyModernTab.SelectedSourceChanged += MyModernTab_SelectedSourceChanged;
void MyModernTab_SelectedSourceChanged(object sender, SourceEventArgs e)
{
if (e.Source.OriginalString.EndsWith("Foo.xaml"))
{
var url = "/Pages/Foo.xaml";
var bb = new BBCodeBlock();
bb.LinkNavigator.Navigate(new Uri(url, UriKind.Relative), this, NavigationHelper.FrameTop);
}
}
I would like to allow users to put a System.Windows.Controls.Button in the System.Windows.Controls.RichTextBox. The button would do a pre-defined thing.
I figured out how to do this. It's called an InlineUIContainer you can do something like this to get it working. Although it doesn't save it into the Xaml
var p = new Paragraph();
var inlineUIContainer = new InlineUIContainer() { Child = new Button() { Content = "This is a Button!" } };
p.Inlines.Add(inlineUIContainer);
_richTextBox.Blocks.Add(p);