I'm using Vaadin 12.0.3 and I'm trying to create a top menu bar using an AppLayout. Therefore I added the AppLayout, which contains the Menu to my main view - the DashboardView (which extends RouterLayout). This view should be the parent view for the MonitoringView which displays some data. Therefore I'm setting the #Route annotation to the MonitoringView like this: #Route(Monitoring.route, layout = DashboardView::class).
The problem is if I add layout = DashboardView::class to the annotation all styling of the MonitoringView is gone. This means texts are not displayed, (background-)colors and shadows are gone and so one. When I remove the layout part from the annotation everything looks fine but then I can't see the menu bar on top.
Here's the code for the mentioned classes:
The DashboardView, which should be the parent for the other view and contains the menu (AppLayout):
#UIScope
#SpringComponent
#Route("dashboard")
#PageTitle("Dashboard")
class DashboardView() : VerticalLayout(), BeforeEnterObserver, RouterLayout {
init {
val appLayout = AppLayout()
val menu = appLayout.createMenu()
menu.addMenuItems(
AppLayoutMenuItem("Page 1", "monitoring"),
AppLayoutMenuItem("Page 2")
)
add(appLayout)
}
}
The MonitoringView that shows monitoring data and should be displayed below the menu bar when the user clicks on "Page 1":
#UIScope
#SpringComponent
#Route("monitoring", layout = DashboardView::class)
class MonitoringView() : VerticalLayout(), BeforeEnterObserver {
...
}
Maybe the #Route property layout needs the java class instead of the Kotlin class?
Try layout = DashboardView::class.java.
See https://kotlinlang.org/docs/reference/reflection.html
Note that a Kotlin class reference is not the same as a Java class
reference. To obtain a Java class reference, use the .java property on
a KClass instance.
Related
I'm working on a Fitness App and try to create something like a menubar which exchanges the container to the right depending on the currently selected menu item. The solution I've come up with until now is that I derive every view that is bound to a menu item from the main view and exchange the container using the replaceWith<ExcerciseEditor>() function. It works but I figure there must be a better solution to this.
// MainView.kt
open class MainView : View("Fit App"){
protected val container: StackPane by fxid()
override val root: AnchorPane by fxml("/view/MainView.fxml")
fun createExercise(){
replaceWith<ExerciseEditor>()
}
// [...]
}
// ExerciseEditor.kt
class ExerciseEditor : MainView(){
init {
container.children += loadFXML<AnchorPane>("/view/ExerciseEditor.fxml")
}
// [...]
}
The app looks like this. The root of this view is a HBox containing two panes: to the left the menu bar and to the right a stack pane containing the other views.
I am trying to follow the guide for type-safe css. Inline styling works but I can seem to get it to work with an a separate stylesheet class. I have tried for every type of control in my program including listviews, buttons, labels, and textfields. No style is applied at all. My button looks like a totally normal button with none of the borders or rotation.
I stripped down my program to be only one button and the exact code from the guide in my stylesheet class.
My main view, stylesheet, and app.
import tornadofx.*
import com.lordxarus.subtitler.app.MyStyles
class MainView : View("Subtitler!") {
override val root = vbox {
button("TEST") {
addClass(MyStyles.tackyButton)
}
}
}
class MyStyles : Stylesheet() {
companion object {
val tackyButton by cssclass()
private val topColor = Color.RED
private val rightColor = Color.DARKGREEN
private val leftColor = Color.ORANGE
private val bottomColor = Color.PURPLE
}
init {
tackyButton {
rotate = 10.deg
borderColor += box(topColor,rightColor,bottomColor,leftColor)
fontFamily = "Comic Sans MS"
fontSize = 20.px
}
}
}
class Subtitler: App(MainView::class, MyStyles::class)
The code works fine, so my guess would be that you're using the TornadoFX IDEA plugin and accidentally ran the View instead of running the App class. The plugin allows you to run views without even defining an app class, but when you do that the framework has no way of knowing that you want to load the stylesheet specified in your app class. Run the Subtitler class instead and you'll see your styles applied :)
My application looks like this (subject to change)
var settingsPage = new NavigationPage(new SettingsPage())
{
Title = "Settings",
Icon = "ionicons_2_0_1_settings_25.png"
};
namespace Japanese
{
public partial class SettingsPage : ContentPage
{
The application works but I am wondering did I make a mistake by having this inherit from a ContentPage even though it works.
Would there be any reason for me to change this to inherit from a Navigation Page? Does a navigation page offer some different methods I might be able to take advantage of later?
This is a fairly standard way to do it. There's nothing wrong with it.
I am new to Xamarin and MVVMCross. So I have created 2 views. Login and Register. I have a button on Login to goto Register view and I am going there by this code in the Login's ViewModel:
// method when user tap register button
public IMvxCommand NavigateRegister
{
get { return new MvxCommand(() => ShowViewModel<RegisterViewModel>()); }
}
It works ok the Register Page opens well. But once I assign Name for a single object on Register view (a textEdit), the app crash when I tap on the Register button.
Below is the error msg:
Xamarin.iOS: Received unhandled ObjectiveC exception:
NSUnknownKeyException [
setValue:forUndefinedKey:]: this class is not key value
coding-compliant for the key regNameEdit.
EDIT:
More details: I already assigned the name (see pic below), but still crash:
And the view also been assigned to its Class "CreateAccount". But I am noticing the class declaration has "partial" darkened out in the "public partial class CreateAccount : MvxViewController" line. That's the only noticeable difference btw this class and the first one.
using MvvmCross.Binding.BindingContext;
using MvvmCross.iOS.Views;
namespace MyApp.iOS.Views
{
public partial class CreateAccount : MvxViewController
{
public CreateAccount() : base("CreateAccount", null)
{
}
public override void ViewDidLoad()
{
base.ViewDidLoad();
// Perform any additional setup after loading the view, typically from a nib.
Title = "Register";
var set = this.CreateBindingSet<CreateAccount, Core.ViewModels.CreateAccountModel>();
set.Bind(regNameEdit).To(vm => vm.NameStr);
}
public override void DidReceiveMemoryWarning()
{
base.DidReceiveMemoryWarning();
// Release any cached data, images, etc that aren't in use.
}
}
}
The Bind(regNameEdit) also is an error (not detecting the textedit still)
This usually means that the a control is not defined in the View/ViewController class in your case the regNameEdit.
Make sure you created the back Property for this Edit and that the class assigned to the XIB is the one containing this property.
If you are using Xamarin Studio Designer you create the back property selecting the UIControl in the XIB/StoryBoard and setting a name, then enter.
This will create a property with the name you specified accessible in the ViewController.
public override void ViewDidLoad()
{
base.ViewDidLoad();
this.MyUITextField.Text = string.Empty;
}
UPDATE
When using Storyboard:
Try this: Remove the name from the TextField and also remove the name from the ViewController class, then clean your project and rebuild. Re-add the class to the ViewController but when doing it click over the yellow icon in the bottom, there put the name and hit enter. Continue with the TextField, select it put the name and hit enter.
UPDATE # 2
When using XIBs
When you create the ViewController from the menu, Xamarin Studio will create both the ViewController class and the XIB file and will associate one with the other so here you don't have to do anything else to link them.
For the TextField you will need to do it adding the name as previously indicated.
Try this: Remove the name of the UITextField and save and clean/rebuild the project then add the name and hit enter.
Something you can do to verify if there's any problem, double click on the button in the XIB and this should take you to the ViewController class to create a method.
Hope this helps.
I use new version of griffon, 1.2.0.
Is there a way to open new window (second view) inside the main app window by clicking button or something?
Assuming the secondary View defines a top level Window container like the following
application(id: 'secondaryWindow', ...) { /* content */ }
and the application's configuration file (Application.groovy) contains an MVC group definition identified by 'secondary' then any controller may popup the window like this
import griffon.transform.Threading
class SomeController {
#Threading(Threading.Policy.INSIDE_UITHREAD_ASYNC)
def showSecondary = {
def group = createMVCGroup('secondary')
app.windowManager.show('secondaryWindow')
}
}