Error: The name 'FindName' does not exist in the current context in my new Class - windows-10-universal

I'm currently creating a new UWApp in C# using Visual Studio 2017. after creating a new Class that will handle all the display of Xaml content.
I transferred a function containing this line of code:
...
Image imgObj = (Windows.UI.Xaml.Controls.Image)FindName("myTopImage");
...
to the new Class but FindName is highlighted in Red with this error message:
The name 'FindName' does not exist in the current context
I'm not sure why FindName is working well in the MainClass and not in the new Class. I've done this before in other App without any issues.
thanks for you time.

What I end up doing to solve the problem:
add a new Content page (xaml+cs)
transferred all my existing xaml & code from the Main to the new page
This way all the controls are out of the Main page and accessible from the new page class. I should have done this from the beginning.

Related

Unable to write the 'tool tip' property for the field 'formName[0].Page6[0].MyGroup[0].3'

I'm updating a new PDF form in Adobe Livecycle Designer 8.0 and keep getting this error when trying to save as either Acrobat 7 or 8 PDF form(.pdf). The issue occurs after copying/pasting fields from an existing PDF to my new one.
I can get around the error by creating new groups and controls, but it would save some time if I could copy/paste and save. Does anyone have a solution for this?
Error message output:
Generating PDF Document... Font Service: Default font typeface is
Myriad Pro. Unable to write the 'tool tip' property for the field
'formName[0].Page6[0].MyGroup[0].3'.
'formName[0].Page6[0].MyGroup[0].3' refers to the 3rd item in the Object Binding tab.
This was the default 'Off' radio button in the group of radio buttons I copied over, which was a hidden field. The solution for me was to delete and re-add only these hidden buttons from any groups. All other controls within the group could be copy/pasted and saved with this exception.

Navigate between views WPF PRISM application

I am working on a WPF PRISM application that has the following structure (I have simplified to explain better without additional layers). I am using Unity as my DI/IOC
AppMain - Bootstrapper
Gui - Views and View Models
Data - Data using EF.
In Gui, I have views names as below:
Home
EmployeesView
OrdersView
Reports
I have three regions in the shell.
MainRegion - Main Content
TopRegion - Navigation Menu
BottomRegion - Status Bar
I am using the following method to register views to the regions
IRegion region = _regionManger.Regions[RegionNames.MainRegion];
var mainView = _container.Resolve<Home>();
region.Add(mainView, ViewNames.HomeViewName);
region.Activate(mainView);
The first of activation happens in the Module Initialize method for Top, Main and Bottom.
After this, I am activating other views when the button are clicked. It is just code behind for now. Sample code here:
IRegion region = _regionManger.Regions[RegionNames.MainRegion];
var reportView = region.GetView(ViewNames.ReportsViewName);
if (reportView == null)
{
reportView = _container.Resolve<ReportsView>();
region.Add(reportView, ViewNames.ReportsViewName);
region.Activate(reportView);
}
else
{
region.RequestNavigate(ViewNames.ReportsViewName);
}
PROBLEM1: Any advise on how this can be done or the way I am doing is fine.
The top menu has Home, Employees, Orders, Reports buttons.
In the home page I have recent orders by the employee in datagrid as readonly.
I would like to double click to navigate to the OrderView and pass the selected order to show to the user. PROBLEM2 I am not sure where to do the navigation for this.
PROBLEM3: Another issue was if set the RegionMemberLifeTime keepAlive false, INavigationAware methods don't fire. If I don't set the KeepAlive to false, the page does not get refreshed because, the view model does not get called.
I need the pages to refresh when it is navigated to and not be stale and also handle any confirm prompts to the user when the view is navigated away from it.
Your help is very much appreciated.
it's certainly too late but…
Problem 1/2: is there a particular reason why you add content to region in module initializer?
the common way is more like -> in xaml:
<ContentControl prism:RegionManager.RegionName="MainRegion" />
and in ModuleInit.cs -> Initialize()
_regionManager.RegisterViewWithRegion("MainRegion", () => _container.Resolve<MainView>());
Problem 3:
the view has to implements INavigationAware, IRegionMemberLifetime
and to swich region, in the viewModel you do:
_regionManager.RequestNavigate("RegionWhatever", new Uri("TestView", UriKind.Relative));
But to work you have to register it in ModulInit.cs as an object with viewName, like that:
_container.RegisterType<Object, TestView>("TestView");
and a contentControl with the correct RegionName define in xaml of course

C#: components cannot show on Windows Form

I have created an empty project. after that, I added new items is Windows Form and add some component such as button or textbox in Design View.
In main file, I use this code:
SimpleForm form = new SimpleForm(); // SimpleForm is my class
form.Show();
But, when I run, C# generate a form but I cannot see textbox nor button. I just see blank area where I put those components. As picture below, the white area is my button, but I don't know why this button cannot show. I think maybe some problem, and those components cannot draw on the form.
Please help me this error.
Thanks :)
If by "the main file" you mean your main method (the entry point) - try this code instead:
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new SimpleForm());
If not you really need to post more of your code to get a reasonable answer.

Combobox clearing value issue

I've stumbled on an issue with Comboboxes in javafx2.2. This is the scenario:
Users click on the 'editFile' button.
Another pane becomes visible (with the setVisible method).
This pane contains 6 comboboxes.
Three of them have fixed items: cboReport, cboSales, cboSend. Three of them get their data from a db (ObservableList) and get populated when the pane becomes visible: cboFile, cboCustomer, cboVet
The user selects a file number from the cboFile. The rest of the comboboxes are beeing set with the correct values.
The user presses the save button, the file gets saved as intended.
Next the user presses a close button.
When the window closes, the data on the pane gets resetted through a resetGUI_editFilePane() method. There is have lines like:
...
cboReport.getSelectionModel().clearSelection();
cboSales.getSelectionModel().clearSelection();
cboSend.getSelectionModel().clearSelection();
cboFile.getSelectionModel().clearSelection();
cboCustomer.getSelectionModel().clearSelection();
cboVet.getSelectionModel().clearSelection();
cboFile.getItems().clear();
cboCustomer.getItems().clear();
cboVet.getItems.clear();
...
When the user opens the pane again by pressing the 'editFile' button I notice that only the 'fixed item' comboboxes have cleared their selection, the dynamicly filled comboboxes show the last selected item although the value from the selection itself is null. This looks like a graphics bug to me or am I doing something wrong?
Is there any way around this issue or what is the best method to reset a combobox?
EDIT 2014/08/27:
This is officially not a bug(clearSelection() does not clear value):
https://bugs.openjdk.java.net/browse/JDK-8097244
The official "workaround" is to clear the value of the ComboBox after clearing selection.
cb.getSelectionModel().clearSelection();
// Clear value of ComboBox because clearSelection() does not do it
cb.setValue(null);
It is very simple. You just need to work with the value property of ComboBox. here you go ....
ComboBox c;
c.valueProperty().set(null);
I hope this works for you :-D
I ran into nearly the exact same situation and came across your question while looking for a solution. Fortunately, I came up with a workaround that forces the ComboBoxes to reset. When you reset the data on your pane, instead of doing something like:
cboVet.getSelectionModel().clearSelection();
cboVet.getItems.clear();
do something like this...
parentNode.getChildren().remove(cboVet);
cboVet = new ComboBox(); // do whatever else you need to format your ComboBox
parentNode.add(cboVet);
You'll also need to do a setItems() again on your ComboBox so the new one will be populated. This is not an ideal solution but it seems to be working as I expect the provided clearSelection() method would.
You can retrieve the items and have them all removed:
cboVet.getItems().removeAll(cboVet.getItems());
I've just tested a working solution with the Java JDK 1.7.11:
combobox.setSelectedItem(null);
combobox.setValue(null);
Hope it helps :)
I use reflection with direct manipulation of buttonCell field in ComboBox skin:
#SuppressWarnings({ "rawtypes", "unchecked" })
public static <T> void resetComboBox(ComboBox<T> combo) {
Skin<?> skin = combo.getSkin();
if(skin==null){
return;
}
combo.setValue(null);
Field buttonCellField;
try {
buttonCellField = skin.getClass().getDeclaredField("buttonCell");
buttonCellField.setAccessible(true);
ListCell buttonCell = (ListCell) buttonCellField.get(skin);
if(buttonCell!=null){
StringProperty text = buttonCell.textProperty();
text.set("");
buttonCell.setItem(null);
}
} catch (NoSuchFieldException
| SecurityException
| IllegalArgumentException
| IllegalAccessException e) {
e.printStackTrace();
}
}
I think it's also possible by providing your own buttonCell implementation through buttonCellFactory property
I had the same problem with a ComboBox. The buttonCell of the ComboBox is not updated correctly when I change the items of the ComboBox. This looks like a graphics bug.
I use direct manipulation of buttonCell field in ComboBox.
combo.getButtonCell().setText("");
combo.getButtonCell().setItem(null);
This is the best solution I've found without recreate the ComboBox.
To clear SelectionModel I found nothing better than creating a new instance of Combobox (previous answers update):
myParentNode.getChildren().remove(myCombobox);
myCombobox = new ComboBox();
myParentNode.add(myCombobox);
But this solution evolves other problems: if you use fxml, this combobox will be placed in the wrong place and with wrong parameters. Some fxml parameters are hardly reproduced directly from your controller class code and this is awful to do it every time you need to clear the combobox.
The solution is using custom components instead of creating instances directly in main controller class code, even if these components are standard. This also helps to free some lines in your main controller class by moving component related event methods and other methods to a separate class file, where you use a reference to your main controller class.
How to create custom components in JavaFX FXML Application can be found in http://docs.oracle.com/javafx/2/fxml_get_started/custom_control.htm , but note that CustomControlExample class is not needed for every custom component in your application, if it already has an entry point class with start(Satge stage) method.
How to resolve possible errors with reference from custom component controller class to main controller class can be found in JavaFx: how to reference main Controller class instance from CustomComponentController class?
I need to clear selection of the combo box. And this code worked for me:
List<Object> list = new ArrayList<>(comboBox.getItems());
comboBox.getItems().removeAll(list);
comboBox.getItems().addAll(list);

How can I access the form used to show a preview of a DevExpress XtraReport?

DevExpress have no simple report viewer control for using an XtraReport on a Windows Form, but simply calling ShowPreview on the report does a great job anyway:
var report = new ClientNameReport();
report.ShowRibbonPreview();
The above code shows a non-model form with my report and a nice ribbon control for doing all the report viewing things one could want, but the caption text of the form is Preview, and I would like to set it to the name of the report. The report has a Container property, but I can't find where this is non-null.
How can I access the form hosting the report and change its caption?
I hope this code fixes your problem:
var report = new ClientNameReport();
var reportPrintTool = new ReportPrintTool(report);
reportPrintTool.PreviewRibbonForm.Text = "Some Text"
report.ShowRibbonPreview();

Resources