---
title: "k.Ui - s&box library"
description: "manage your UI (open, close from code easily)"
canonical: "https://sbox.watch/libraries/kfe/kui/"
generated_at: "2026-07-22T23:14:22.744Z"
---

# k.Ui

manage your UI (open, close from code easily)

- Type: library
- Ident: kfe.kui
- Creator: k0fe
- Canonical: https://sbox.watch/libraries/kfe/kui/
- Markdown: https://sbox.watch/libraries/kfe/kui.md
- sbox.game: https://sbox.game/kfe/kui/
- Generated: 2026-07-22T23:14:22.744Z

## Stats

- 24h momentum: +0
- Terry score: --
- Favorites: 0
- Upvotes: 0
- Downvotes: 0
- Updated: Apr 6, 2025
- Created: Apr 1, 2025
- Size: 17.7 KB
- Files: 40
- Tags: ui

## Description

Manage your screens a bit easier.

Start
- Create UI config | Asset Browser | Right click -> k.UI -> UiConfig
- Create prefab for each view, add Screen Panel, Razor component and class that inherits from ViewBase
- Register your prefabs in the config
- Add UiInitializer on your initialization scene and pick your UiConfig

Make a View
- Create script derived from ViewBase

public class ExampleView : ViewBase
{
}- Attach script to your UI window prefab
- Reference prefab in UiConfig

Open a View
Ui.Open<ExampleView>();

Close a View
Ui.Close<ExampleView>();
How to pass a custom data model
- Create a model

public class PlayerViewModel : ViewModelBase
{
 public string Name { get; set; }
 public int Health { get; set; }

 // we will add constructor for ease of use
 public PlayerViewModel( string name, int health )
 {
 Name = name;
 Health = health;
 }
}

- Override OnViewModelUpdate method in your target ViewBase class
- Cast (!) your data model and process your data

public class PlayerInfoView : ViewBase
{
 \[Property\] public PlayerHUD PlayerHUD { get; set; }
 public override void OnViewModelUpdate( ViewModelBase model )
 {
 base.OnViewModelUpdate( model );
 if ( model is PlayerViewModel playerViewModel )
 {
 PlayerHUD.SetPlayerViewModel( playerViewModel );
 }
 }
}

- Now you can open your UI with a data model

Ui.Open<PlayerInfoView>( new PlayerViewModel( "k0fe", 100 ) );

Be aware, that OnViewModelUpdate is better to be avoid when we want to update UI often. Instead we should use BuildHash in Blazor or anything else. OnViewModelUpdate is better used when we want to inject specific classes in our ViewBase classes.



## More by k0fe

| Package | Ident | Players | Favorites | Upvotes | Score | Markdown |
| --- | --- | --- | --- | --- | --- | --- |
| k.ECS | kfe.kecs | 0 | 2 | 3 | 53% | https://sbox.watch/libraries/kfe/kecs.md |
| k.Cameras | kfe.kcameras | 0 | 1 | 0 | -- | https://sbox.watch/libraries/kfe/kcameras.md |
| k.Constraints | kfe.kconstraints | 0 | 1 | 0 | -- | https://sbox.watch/libraries/kfe/kconstraints.md |
| k.Clothing | kfe.kclothing | 0 | 0 | 0 | -- | https://sbox.watch/libraries/kfe/kclothing.md |
| k.DlContainer2 | kfe.kdlcontainer2 | 0 | 0 | 0 | -- | https://sbox.watch/libraries/kfe/kdlcontainer2.md |
| k.Extensions | kfe.kextensions | 0 | 0 | 0 | -- | https://sbox.watch/libraries/kfe/kextensions.md |
