How to notify when childwindow appear - silverlight-4.0

At my application i would like to monit when childwindow appear. I could use some event in childwindow, but i preffer some more generic solution, one function which will be invoke when childwindow is opening...
Something like
Application.Current.RootVisual.ChildWindowOpened - but unfortunetly not such even in silverlight.
Thanks in advance.

As the ChildWindow must be manually invoked, you could create a helper method like this:
public void OpenChildWindow()
{
ChildWindow1 CW = new ChildWindow1();
CW.Show();
if (ChildWindowOpened != null)
ChildWindowOpened(this, null);
}
public event EventHandler ChildWindowOpened;

Related

Unable to send EVT_COMMAND from one class to another

I'm just starting with wxWidgets and I've run into a problem.
I have a mainwindow and another class derived from wxDialog. The main window launches the dialog box in non-modal mode. When the dialog closes, it posts an event but the handler for this event never gets called.
I'm using wxWidgets 3.1.5
The above two classes share a common header file, in which I have this code
wxDECLARE_EVENT(EVT_VISOR, wxCommandEvent);
This is my event table
BEGIN_EVENT_TABLE(VisorFrame, wxFrame)
....
EVT_COMMAND(ID_DlgDisplayLogsTerminated, EVT_VISOR, VisorFrame::OnDlgDisplayLogsTerinated)
....
END_EVENT_TABLE()
In the class derived from wxDialog, I have this at the top of my file
wxDEFINE_EVENT(EVT_VISOR, wxCommandEvent);
This is my event handler
void
VisorFrame::OnDlgDisplayLogsTerinated(wxCommandEvent& event)
{
wxPuts(_("VisorFrame::OnDlgDisplayLogsTerinated ent"));
}
And finally, this is how I post my event
void
DlgDisplayLogs::OnClose(wxCloseEvent& ev)
{
wxPuts(_("send event"));
wxCommandEvent event(EVT_VISOR, ID_DlgDisplayLogsTerminated); // enum value
event.SetEventObject(this);
event.SetString("Hello");
QueueEvent(event.Clone());
ev.Skip();
}
I have followed the documentation but I must be doing something wrong!
I think you're nearly there. I think what you could do is pass the wxFrame as a parent to your modeless dialog and post the event via the parent.
wxCommandEvent event(EVT_VISOR, ID_DlgDisplayLogsTerminated);
event.SetEventObject(this);
event.SetString("Hello");
wxPostEvent(frameParentPtr, event);
And in your wxFrame event table:
EVT_COMMAND(wxID_ANY, EVT_VISOR, VisorFrame::OnDlgDisplayLogsTerinated)

Helix Toolkit How to use MouseWheelEventHandler to run specific methods in other classes

I would like to run particular methods of a custom Camera class whenever the user zooms in or out in the helix toolkit view that my program is running inside of.
A key feature of this functionality is getting the mouseargs from the event so I can adjust the camera in a way that is proportional to the number of scroll ticks.
I began to try this:
public event PropertyChangedEventHandler PropertyChanged;
public virtual void onMouseWheeled(MouseDevice Mouse, int time,
MouseWheelEventArgs e) {
MouseWheel?.Invoke(this, new MouseWheelEventArgs(Mouse, time,
e.Delta)); }
//This next line goes in a MainWindow_Loaded method that gets called in the
//MainWindowConstructor
void MainWindow_Loaded(object sender, RoutedEventArgs e) {
view1.MouseWheel += new MouseWheelEventHandler(onMouseWheeled(Cursor,
Time.simTime, view1.MouseWheeledEventArgs)); }
but was having a lot of trouble figuring out how to pass a MouseWheelEventArgs object into the onMouseWheeled method when I'm trying to add the onMouseWheeled method to the MouseWheelEventHandler. Assuming nothing is fundamentally wrong with that sentence, which is nothing more than wishful thinking, The last thing I am trying to figure out is how to get mouse wheel event args so that I can pass it into a method.
Then I tried this:
public event MouseWheelEventHandler MouseWheel;
public virtual void onMouseWheeled(object sender, MouseWheelEventArgs e)
{
Console.WriteLine(e.Delta);
}
//In Main Window Loaded method...
void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
view1.MouseWheel += onMouseWheeled;
}
But I get no output when i scroll the wheel. I assumed this might actually work because view1 is the helix window I'm attaching all of my objects to, as children of view1.
Basically my main questions are:
What does invoke actually do? I only have this running to try to see if its working because onPropertyChanged methods I always use run the Invoke command like so. I'm actually not sure where I'm going with this.
How does the handler work?
How do the event args get called out so that I can use them and pass them as objects to other methods?
Thank you for your time. And Thank you twice for any and all pointers and advice you may give me.
Try to use preview mouse wheel event

How to execute a binding for a metro control

I want to write the contents of a per occasion active TextBox back to the bound property of the ViewModel when the user presses the key combination for save (Ctrl-S).
My Problem with it is, that I'm not able to trigger the execution of the binding so that the bound Text-Property reflects the contents of the TextBox.
-There seems to be no GetBinding-method. Therefore I can not get the Binding and execute it manualy.
-There is no Validate-method such as in WinForms which executes the Binding
-Giving focus to another control from within KeyDown seems not to work, the binding does not execute
How can I achieve this?
Take a look at Aaron's discussion about this in his WiredPrarie blog post : http://www.wiredprairie.us/blog/index.php/archives/1701
I think I understand your question better now. One way around this would be to use a sub-classed textbox with a new property like this from here:
public class BindableTextBox : TextBox
{
public string BindableText
{
get { return (string)GetValue(BindableTextProperty); }
set { SetValue(BindableTextProperty, value); }
}
// Using a DependencyProperty as the backing store for BindableText. This enables animation, styling, binding, etc...
public static readonly DependencyProperty BindableTextProperty =
DependencyProperty.Register("BindableText", typeof(string), typeof(BindableTextBox), new PropertyMetadata("", OnBindableTextChanged));
private static void OnBindableTextChanged(DependencyObject sender, DependencyPropertyChangedEventArgs eventArgs)
{
((BindableTextBox)sender).OnBindableTextChanged((string)eventArgs.OldValue, (string)eventArgs.NewValue);
}
public BindableTextBox()
{
TextChanged += BindableTextBox_TextChanged;
}
private void OnBindableTextChanged(string oldValue, string newValue)
{
Text = newValue ? ? string.Empty; // null is not allowed as value!
}
private void BindableTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
BindableText = Text;
}
}
Then bind to the BindableText property.
Solution for command-instances
Here a solution I have found which is relatively leightweight, but also a bit "hackish":
btn.Focus(Windows.UI.Xaml.FocusState.Programmatic);
Dispatcher.ProcessEvent(CoreProcessEventsOption.ProcessAllIfPresent);
btn.Command.Execute(null);
First I give the focus to another control (In my case the button which has the bound command). Then I give the system time to execute the bindings and in the end I raise the command which is bound to the button.
Solution without bound commands
Give the Focus to another control and call the Dispatcher.ProcessEvent(...).
anotherControl.Focus(Windows.UI.Xaml.FocusState.Programmatic);
Dispatcher.ProcessEvent(CoreProcessEventsOption.ProcessAllIfPresent);
// Do your action here, the bound Text-property (or every other bound property) is now ready, binding has been executed
Please see also the solution of BStateham.
It's another way to solve the problem

How to make a propertysheetpage be a selection provider?

I've got a contributed command and a handler for it. The handler's execute event has to get the value for the property actually selected in the properties view and act on it, or to be disabled if no property selected.
I've tried:
1) Set the selection provider to something which provides selection from the property view. Something in this case is just PropertySheetViewer for my PropertySheetPage, but i can't set it as the selection provider because the PropertySheetPage's viewer is private and has no getter.
2) Overriding PropertySheetPage's createControl method: This method creates a Tree control for the PropertySheetViewer. A selection listener can be installed for that tree control, so maybe i can make my command handler implement SelectionListener... The solution would be somethin like:
In my editor:
public Object getAdapter(#SuppressWarnings("rawtypes") Class type) {
if (type == IPropertySheetPage.class) {
PropertySheetPage page = new PropertySheetPage() {
#Override
public void createControl(Composite parent) {
super.createControl(parent);
IHandler handler = someWayToGetMyCmdHandler();
((org.eclipse.swt.widgets.Tree) getControl())
.addSelectionListener(handler);
}
};
IPropertySheetEntry entry = new UndoablePropertySheetEntry(
getCommandStack());
page.setRootEntry(entry);
return page;
}
return super.getAdapter(type);
}
And my command handler implementing SelectionListener as i said... The problem with this approach is that i can't find a way to get a reference to my contributed command handler (someWayToGetMyCmdHandler() above).
Has anybody got any clue on this, or any other possible approach to the problem??
There's handleEntrySelection(ISelection selection) method in PropertySheetPage that you could override to be notified about selection changes in the viewer (although PropertySheetPage is #noextend).
The second part (updating the handler) is a bit more tricky than it would normally be. Commands/handlers get updated automatically when workbench selection changes (you just need to implement setEnabled(Object evaluationContext) AbstractHandler). But since PropertySheetPage is designed to change its input on global selection change, then you have to find some custom way to notify/update your handler.
As I understand, it is currently not possible to extend the platform command event handling mechanism with custom variables, so you just need to directly look up your handler using IHandlerService of the workbench.

SetCompatibleTextRenderingDefault in .NET Class Library containing a form

I have a .net class library with a com class that calls a form.
I want to to SetCompatibleTextRenderingDefault(false) to ensure the form fonts look nice.
If I run the command in the class constructor I get the following error:
SetCompatibleTextRenderingDefault must be called before the first IWin32Window object is created in the application.
Where can/should I run this? Surely there is no earlier place than sub New!
Thank in advance
Jon
Edit1: To clarify, I get this error when initiating the class from a .net test harness, if I call it from a VB6 app then I simply get "Automation Error"
Edit2: Is the answer that I cannot use SetCompatibleTextRenderingDefault in a com class when calling from a vb6 app?? Maybe it's the "parent" app that needs to call this method and as such a vb6 app cannot?
Edit3: Maybe I am asking this question in the wrong way! - Maybe the question is: how can I make the fonts look nice in a .net class library form called from a vb6 app?
A possible workaround would be to set the property manually on all buttons and labels in the form constructor:
public Form1()
{
InitializeComponent();
DisableCompatibleTextRendering(this);
}
private static void DisableCompatibleTextRendering(Control c)
{
var button = (c as ButtonBase);
var label = (c as Label);
if (button != null)
{
button.UseCompatibleTextRendering = false;
}
if (label != null)
{
label.UseCompatibleTextRendering = false;
}
foreach (var child in c.Controls.Cast<Control>())
{
DisableCompatibleTextRendering(child);
}
}
Place this inside the application startup code before the first window is created. Under C# this would be the main routine that then creates the initial window.