I have a resource dictionary file in my app (Themes\MyDictionary). There is a control template with the x:Key property. How to get it in code?
1) Create a new ResourceDictionary object.
2) Set the ResourceDictionary.Source property pointing to the XAML file with the Page build action.
3) Get template by string key.
static object GetDefaultToolTipTemplate() {
// 1)
ResourceDictionary rd = new ResourceDictionary() {
// 2)
Source = new Uri(#"ms-appx:///Themes/ToolTip.xaml", UriKind.Absolute)
};
// 3)
ControlTemplate template = (ControlTemplate)rd["DefaultStyleForTooltipInControlTooltipOwner"];
return template;
}
Related
I need to change the "title" for each document shown in ICN Viewer, dynamically, at runtime. I'll read the new viewer tab title from the document properties
ENVIRONMENT: ICN 2.0.3 CM8.5 WAS 8.5.5
CODE SO FAR:
I found a PARTIAL solution by hooking "ecm.model.desktop, onChange":
aspect.after(ecm.model.desktop, 'onChange', function() {
var contentViewer = dijit.byId('contentViewer');
if (contentViewer) {
var viewerTabTitleDef = new ViewerTabTitleDef ();
contentViewer.mainTabContainer.getChildren().forEach(function(child) {
viewerTabTitleDef.changeTitle(viewerTabTitleDef.self,
child.controlButton, child.contentViewerPane.viewerItem.item);
});
...
I was able to extend this for subsequent documents opened in the same viewer, and optimized by "removing()" the handler after this initial call. Here is the complete code:
var kill = aspect.after(ecm.model.desktop, 'onChange', function() {
var contentViewer = dijit.byId('contentViewer');
// "contentViewer" will be "unknown" unless viewer invoked
console.log('onChange: contentViewer', contentViewer);
if (contentViewer) {
console.log("new ViewerTabTitleDef()...");
kill.remove();
var viewerTabTitleDef = new ViewerTabTitleDef ();
contentViewer.mainTabContainer.getChildren().forEach(function(child) {
// For initially opened tabs
console.log('initially opened: child', child);
viewerTabTitleDef.changeTitle(viewerTabTitleDef.self, child.controlButton, child.contentViewerPane.viewerItem.item);
});
aspect.after(contentViewer.mainTabContainer, 'addChild', function(child) {
// For tabs added after the viewer was opened
console.log('subsequently opened: child', child);
viewerTabTitleDef.changeTitle(viewerTabTitleDef, child.controlButton, child.contentViewerPane.viewerItem.item);
}, true);
} // end if contentViewer
}); // end aspect.after(onChange desktop)
CURRENT PROBLEM:
Q: How can I change the label for a split tab (either vertical or horizontal)?
So far, I have NOT been able to find any event for any ICN/ECM widget or object variable that I can trigger on.
Thank you in advance!
===============================================
ADDENDUM:
Many thanks to Ivo Jonker, for his suggestion to modify the widget prototype's
"getHtmlName()" method. It worked!
Specifically:
I'm invoking this code from an ICN plugin. I set event handlers in my plugin's base .js file, but it actually gets invoked in the new, separate viewer window.
The original prototype looked like this:
getHtmlName: function() {
var methodName = "getHtmlName";
this.logEntry(methodName);
var displayName = this.item.getDisplayValue("{NAME}");
if (displayName == "") {
displayName = this.item.name;
}
var htmlName = entities.encode(displayName);
this.logExit(methodName);
return htmlName;
},
Per Ivo's suggestion, I overrode the prototype method like this:
myPluginDojo.viewerTabTitleDef = viewerTabTitleDef;
...
ecm.widget.viewer.model.ViewerItem.prototype.getHtmlName = function () {
console.log("NEW getHtmlName()...");
var displayName = myPluginDojo.viewerTabTitleDef.getTitle(this.item);
return displayName;
};
If i understand you correctly, you want to show a different tab-title (instead of the document title) in the navigator viewer whenever a doc is opened?
How about this:
Every document you open in the viewer is wrapped in a ecm.widget.viewer.model.ViewerItem which exposes the getHtmlName that returns the name used in the tab.
Your solution would be to implement your own getHtmlName.
Unfortunately though, the ViewerItem is constructed in the ecm.widget.viewer.ContentViewer#_open and then passed to the ecm.widget.viewer.ContentViewer#_openTab. So you'll either violate best practice by mingling with IBM private method's, or you'll go for a generic approach and just replace the ecm.widget.viewer.model.ViewerItem.prototype.getHtmlName
I'm working on a Leave Request form on our Google site. If I comment out the app.createServerHandler line it is fine. What am I missing from the below code?
var app = UiApp.createApplication().setTitle('OIT Leave Request');
//Create a panel to hold the form elements
var panel = app.createVerticalPanel().setId('panel');
//Create event handlers for form
var AllDayBoxHandler() = app.createServerHandler('AllDayBoxEvent');
Check this link.
I believe what you're trying to do is depreciated. But either way I think your setting the handler wrong. Something like:
function doGet(e) {
var app = UiApp.createApplication().setTitle('OIT Leave Request');
//Create a panel to hold the form elements
var panel = app.createVerticalPanel().setId('panel');
app.add(panel);
//Create event handlers for form
var AllDayBoxHandler = app.createServerHandler('AllDayBoxEvent');
//Not exactly sure what events a panel can get
//A button would have a .addClickHandler method
panel.addOpenHandler(AllDayBoxHandler);
return app;
}
//The event handler method
function AllDayBoxEvent(e) {
// your code
}
I've got a problem and hope you can help me.
I have multiple QQmlWidgets where different instances of same components should be shown.
The components are created at runtime and use specific properties from it's parent widget.
The problem is, that there are multiple nested items in those components, so they are loading very slow.
I've decided to load them all to QQmlEngine at application preload stage, and after just create them when necessary.
So all my QQmlWidgets got same QQmlEngine and same root context.
To differ properties of different widgets I'm creating every instance of component in separate context (one per QQmlWidget).
After creating I'm setting parent item of newly created object to root item of QQmlWidget;
The problem is that the root item is referenced in the dynamically created objects and they could not find it.
Can you suggest any solution? I'm posting simplified version of my code below.
// main.cpp
QQmlEngine* e = new QQmlEngine;
QWidget* ww1 = new QWidget;
QWidget* ww2 = new QWidget;
QQuickWidget* w1 = new QQuickWidget(e, ww1);
QQuickWidget* w2 = new QQuickWidget(e, ww2);
w1->setSource(QUrl::fromLocalFile("main.qml"));
w2->setSource(QUrl::fromLocalFile("main.qml"));
QQmlComponent* comp = new QQmlComponent(e, "comp.qml");
QQmlContext* c1 = new QQmlContext(e);
QQmlContext* c2 = new QQmlContext(e);
QQuickItem* it1 = qobject_cast<QQuickItem*>(comp->create(c1));
it1->setParentItem(w1->rootObject());
QQuickItem* it2 = qobject_cast<QQuickItem*>(comp->create(c2));
it2->setParentItem(w2->rootObject());
ww1->show();
ww2->show();
//main.qml
Rectangle {
id: root
}
//comp.qml
Rectangle {
anchors.top : root.top
}
the error:
comp.qml - ReferenceError: root is not defined
Thanks in advance.
When a component is being loaded a parent is not set and it becomes set only after call of setParentItem method. It can be fixed by setting anchor when parent changes.
// comp.qml
Rectangle {
onParentChanged: { anchors.top = parent.top; }
}
I have a Google Script published as a web app which uses UI service to display an interface with several listboxes. I can get at the values selected thru server handlers.
My problem is that I need to add these values to a url in a anchor defined in my doGet routine. (I am calling a JotForm url, and need the dynamic parameters to pre-populate the form)
I can't see how to modify the anchor from the handler function, or any other way to invoke the url I build in code.
When you want to modify any widget in a Ui created with UiApp, each widget must have an ID that you can use to getElementById() and manipulate the way you want just as if you were in the doGet function.
Here is a simple example to illustrate : (online here)
function doGet(){
var app = UiApp.createApplication().setTitle('test');
var serieNames = [' serie A',' serie B',' serie C'];
var panel = app.createVerticalPanel().setStyleAttribute('padding','30px');
var namesHandler = app.createServerHandler('showPilots').addCallbackElement(panel);
for(var n in serieNames){
var serieSelect = app.createRadioButton('pilotSelect',serieNames[n]).setId('s'+n).addClickHandler(namesHandler)
panel.add(serieSelect);
}
app.add(panel);
return app;
}
function showPilots(e){
Logger.log(JSON.stringify(e));// you can see the source parameter in e that returns the widgets ID of the button you clicked to call the handler
var app = UiApp.getActiveApplication();
var serie = e.parameter.source; // get the ID
app.add(app.createLabel('you clicked '+e.parameter.source));// then get this widget by its ID and modify it
app.getElementById(serie).setText('Clicked');// modify it
return app;// update Ui
}
EDIT : here is a version that manipulates anchors, it is perfectly possible to change the url from a handler.
test here
code :
function doGet(){
var app = UiApp.createApplication().setTitle('test');
var links = ['link 1',' link 2',' link 3'];
var linkshref = ['http://www.google.com','http://www.packtpub.com/google-apps-script-for-beginners/book','http://stackoverflow.com/questions/tagged/google-apps-script'];
var panel = app.createVerticalPanel().setStyleAttribute('padding','30px');
var namesHandler = app.createServerHandler('changeUrl').addCallbackElement(panel);
for(var n in links){
var linkWidget = app.createAnchor(links[n], linkshref[n]).setId('s'+n);
panel.add(linkWidget);
}
var btn = app.createButton('change links',namesHandler);
app.add(panel.add(btn));
return app;
}
function changeUrl(e){
Logger.log(JSON.stringify(e));// you can see the source parameter in e that returns the widgets ID of the button you clicked to call the handler
var app = UiApp.getActiveApplication();
var links = ['New link 1','New link 2','new link 3'];
var linkshref = ['http://www.microsoft.com','http://www.w3schools.com/js/','https://sites.google.com/site/appsscriptexperiments/'];
for(var n in links){
app.getElementById('s'+n).setHref(linkshref[n]).setHTML(links[n]);
}
return app;// update Ui
}
I use MVVM Light Framework for a metro style app.
I want add a command in SettingsPane to show an about page. The about page should be displayed on the right (like preinstalled calendar app). For a test I have added following line in OnLaunched method in App.xaml.cs:
SettingsPane.GetForCurrentView().CommandsRequested += App_CommandsRequested;
and following event handler:
void App_CommandsRequested(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs args)
{
// Add an About command
var about = new SettingsCommand("about", "About", (handler) =>
{
// show about page in flyout transition...
});
args.Request.ApplicationCommands.Add(about);
}
Is this the only way?
How can I flyout the about page? Any tips...?
Thanks for help!
Michael
to answer the first question:
as far as I know, This is the only way to do something like that.
To answer the second question:
To flyout the the about page you can do this:
// Add an About command
var about = new SettingsCommand("about", "About", (handler) =>
{
// show about page in flyout transition...
var currentPane = new AboutPane(); // the aboutpane is a page
var myPopup = new Popup();
myPopup.IsLightDismissEnabled = true;
myPopup.Width = _settingsWidth;
myPopup.Height = Window.Current.Bounds.Height;
myPopup.Width = 346;
myPopup.Height = Window.Current.Bounds.Height;
myPopup.Child = currentPane;
myPopup.SetValue(Canvas.LeftProperty, Window.Current.Bounds.Width - 346);
myPopup.SetValue(Canvas.TopProperty, 0);
myPopup.IsOpen = true;
});
args.Request.ApplicationCommands.Add(about);
I hope this will solve you're problem.
Michael, try using the SettingsFlyout control from the Callisto project on github
You will need something like:
using Callisto.Controls;
//... other code here
//in your callback for handling the settings command:
// show about page in flyout transition...
var settingsFlyout = new SettingsFlyout();
settingsFlyout.Content = new AboutControl(); //this would be your own user control that contains the about page content
settingsFlyout.IsOpen = true;