Today, I got a new problem while printing the uwp app, that the print preview could not be generated if I remove and then again add my usercontrol into the main page.
My scenario: I have a user control in which I have a listbox whose items are horizontally aligned but I want to print these items (2 items per page) in vertical fashion.
So, I have created another same listbox with vertical aligned items and initially this listbox is hidden then while creating the preview this listbox is displayed for a while.
Now, the issue is for the very first time when I run my application then it works like a charm then after removing the same usercontrol and adding it again is creating a problem for me and the print preview could not be generated.
I have created a stripped down sample replicating this issue.
Steps to reproduce:
Run the application.
Click on "Load contacts" button
Click on "Print" button
Observe: A print dialog is opened and the print preview is created -- Correct
Now, cancel the printing process to hide the print dialog
Click on "Clear" button to remove the usercontrol
Now, repeat the steps from 1 to 3
Observe: This time, print preview is not created ---- Incorrect
Demo sample link: https://1drv.ms/u/s!AiCx3o82H3zN9XD8iNCnaUmHUpzI
In the Unloaded event , when you set the null to the PrintManager that you can not remove the PrintManager.PrintTaskRequested event from it. It will throw the "Delegate to an instance method cannot have null 'this'."
You should be able to remove the PrintManager.PrintTaskRequested event before the PrintManager is be set the null.
For example:
private void ContactsUserControl_Unloaded(object sender, RoutedEventArgs e)
{
try
{
printMan.PrintTaskRequested -= PrintTaskRequested;
printMan = null;
printDocSource = null;
printDoc.Paginate -= Paginate;
printDoc.GetPreviewPage -= GetPreviewPage;
printDoc.AddPages -= PrintDoc_AddPages;
printDoc = null;
GC.Collect();
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
}
Related
I've created a custom field in Vaadin14 that displays a grid and two buttons (add row / clear grid). This custom field is displayed in a CRUD editor, editor that in turn has tabs.
For creating the grid with editor I've used the example shown here https://vaadin.com/docs/v14/ds/components/grid in the "Non-buffered" section.
Everything works as expected except for the addCloseHandler(Component, Editor). In the example shown above the code for the close handler method is this one:
textField.getElement().addEventListener("keydown", e -> editor.cancel()).setFilter("event.code === 'Escape'");
which closes the editor when pressing the Esc key or clicking outside the cell that's in edit mode.
My problem is that, given the grid with the editor are inside a CRUD form when I'm hitting Esc the CRUD discard changes form is being shown instead of the editor closing. Also, when clicking outside the edited cell nothing happens.
I believe this is due to the "event.code" in the setFilter method being incorrect but I'm unsure how to determine what is the proper event code that's being triggered in my case.
I tried changing the event from "keydown" to "focusout" which led to the callback method being called when I clicked outside the cell that was being edited but nonetheless the editor did not close (I.e. the cell was stuck in edit mode). I also tried calling editor.close() inside the callback method but with no success.
From https://vaadin.com/docs/v14/ds/components/grid in the "Non-buffered" section:
In the example below, double-click a row to start editing. Press
Escape, or click on a different row to stop editing.
This kotlin code has exactly the same behavior
var clickRegistration :Registration? = null
fun addCloseHandler(field: Component, editor: Editor<*>) {
field.element.addEventListener("keydown") { event ->
editor.cancel()
clickRegistration?.remove()
}.filter = "event.key === 'Escape'"
}
grid.addItemDoubleClickListener { e: ItemDoubleClickEvent<DataSet?> ->
editor.editItem(e.item)
val editorComponent = e.column.editorComponent
if (editorComponent is Focusable<*>) {
(editorComponent as Focusable<*>).focus()
}
clickRegistration = grid.addItemClickListener { event ->
editor.cancel()
clickRegistration?.remove()
}
}
You must use event.key not event.code:
getElement().addEventListener("keydown", event -> editor.cancel())
.setFilter("event.key === 'Escape' || event.key === 'Esc'");
I'm trying to fire an event programmatically. My problem is that I have two SVG on two DIVs and I want to be able to change the border of the DIV I have clicked. To do that I thought to pass the DIV inside my classes and then trigger a click on it once I click on anything. (if there is a better way, please tell me)
I have the following code:
div = querySelector(divName);
svgElement = new svg.SvgSvgElement();
div.append(svgElement);
div.onClick.listen(_setBorders(1));
later I pass the svgElement to another class
ell.show(svgElement);
where show is
show(svg.SvgElement element) {
if (element.parent is DivElement){
_parentDiv= element.parent as DivElement;
element.children.add(_group);
}
}
_parentDiv is of course a DivElement, which I use for an internal onClick()
_onClick(MouseEvent e) {
window.console.info("onClick Ell");
_parentDiv.click();
}
I'm expecting to see the _setBorders(1); I defined with the main div, but it doesn't work. The weird thing is that when I check with the debugger set to the _parentDiv.click() I see that _parentDiv has the event correctly set.
I suppose click() doesn't work as I expected. Any Idea?
If you want that _setBorders(1) is called on click events you have to use :
div.onClick.listen((_) => _setBorders(1));
I have several TextField's inside a window along with a Button, e.g. aButton.
The TextField's, Button, and window all have setImmediate(True).
When a TextField loses focus some validation code is executed and if it fails it calls:
aButton.setEnabled(False);
When incorrect data is entered into one TextField and then focus is lost the debugger shows that aButton.setEnabled(False) is called but aButton still looks enabled.
Two possible things can happen from here:
1.) If one modifies data in another TextField and exits that field (loses focus), the validation can be successful or not for that field but the system knows to call aButton.setEnabled(False) as the previous TextField is still invalid. This time though aButton is visually disabled.
2.) If one clicks on aButton which is visually enabled it produces this warning then visually becomes disabled:
Warning: Ignoring variable change for disabled component < class 'ui.button.Button'>, caption=OK
Currently using Vaadin 6.7.3
Are there any known work arounds to force aButton to visually become disabled immediately (force the client to update) after manually setting it to be disabled?
Sadly I have only Vaadin 7 at my disposal right now, but I checked this anyway. It works as you wanted it to work and I have to jump to the conclusion that this should be the same in Vaadin 6.7.3. This part is not really different in Vaadin7... Have you tried this feature in an isolated code (only a textbox and the button)?
VerticalLayout vlTestContent = new VerticalLayout();
final Button butChangeMe = new Button("Enabled");
final TextField tf = new TextField("Blur", "default value");
tf.addBlurListener(new BlurListener() {
private static final long serialVersionUID = 5544993392287938660L;
#Override
public void blur(BlurEvent event) {
butChangeMe.setCaption("Disabled");
butChangeMe.setEnabled(false);
}
});
Button but = new Button("Change button", new ClickListener() {
private static final long serialVersionUID = -2235317499126190105L;
#Override
public void buttonClick(ClickEvent event) {
butChangeMe.setCaption("Enabled");
butChangeMe.setEnabled(true);
}
});
vlTestContent.addComponent(butChangeMe);
vlTestContent.addComponent(tf);
vlTestContent.addComponent(but);
(The second button is just for fun)
button.setVisible(false) will always work. You need to be careful to not fire up a another event on the focus lost event that ends up setting the visibility of the button to true.
You can request a repaint of a component or the whole window, but the whole point of the framework is that you will never need to do that, because visually modified components will automatically repaint on each request.
Just to be curious, do you let your request to finish before trying to see if the browser updates? Or you look at your browser right after you pass the setVisible() line in your debugger ?
I think that your point nr 2 happens because you clicked on the button, and what happens in this order is: 1st your focus lost event runs (which probably disables your button), 2nd button click runs and somehow a repaint is requested for that button because a state change happened in the button but a repaint show the warning that it won't do anything with it because it is disabled (was just disable by the focus lost event)
As a side note. I think this UI won't make for a good user experience, it should be the other way arround, if a validation is ok, then show the button (or better, always show the button, but enable/disable instead) But it depends...
I have one fragment activity include two list fragments.
I use D-pad to moving through lists.
For example, when I click on listview1->tv, in listview2 shows tv channels
. When I click listview1->movie, in listview2 shows movies list and so on.
So this is my problem: when I click listview1->item3 (item3 is highlighted now by a selector) and go to listview2 and use d-pad up/down to surf the items then I come back to listview1, by left arrow key, I expect to going back to listview->item3. But it's not the case and I can't gust witch item in listview1 will focused (highlighted)
I can't handle the focused item, I need to go back to last selected item (getListView().getSelectedItemPosition()) has true item position number but focused/hilighted is not in true/last postion)
Android 2.3.4
I used these methods but none worked
getListView().setOnFocusChangeListener(new OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean focused) {
// TODO Auto-generated method stub
if (!focused) allowfocus=true;
if (focused && allowfocus){
getListView().setSelection(PosHolder.MENU_LAST_POS);
OR
getListView().setSelection(getListView().getSelectedItemPosition());
OR
getListView().getSelectedView().setSelected(true);
OR
getListView().getSelectedView().requestFocus();
Toast.makeText(getActivity(), "Menu Got Focused:"+ getListView().getSelectedItemPosition(), Toast.LENGTH_SHORT).show();
}
}
});
What worked for me was to create a customListView which inherits from the original ListView, and then override the OnFocusChange Event to handle your focus in there.
I am having a bit of a problem with an app I'm developing for BlackBerry.
I have a series of Item objects on the screen, each with a DefaultCommand tied to it. Example
below:
...
cmdBrowse = new Command(temp.id,Command.ITEM,0);
mainList.setDefaultCommand(cmdBrowse);
mainList.setItemCommandListener(icl);
...
Previously just clicking on the item with the confirm button would run the proper command. No problem there.
Then I added the handleKeyReleased method to capture the BlackBerry's back button as follows:
protected boolean handleKeyReleased(int keyCode, int gameAction) {
if(keyCode==1769472) {
/*code to deal with back button*/
return true;
} else {
return false;
}
}
Now when I click on the mainList Item with the confirm button, it brings up the list of commands first and I have to click again to actually run the command. Two clicks where it used to be one.
So, is there a way to either:
A. Keep the single click behaviour while still being able to capture the back button with handleKeyReleased
or
B. Capture the back button in a different way ?
I ended up overlooking one very simple thing. All I had to do was call the superclass's handleKeyReleased method and everything worked perfectly.