Simple window with button crashes

Pulled from the docs, just trying to get a button to show up. The gradient shows up fine until I add the button as a child.

class Program : Application
{
    public Program(DisplayController d) : base(d)
    {
    }

    static Program app;

    static void Main()
    {
        GpioPin backlight = GpioController.GetDefault().OpenPin(SC20260.GpioPin.PA15);
        backlight.SetDriveMode(GpioPinDriveMode.Output);
        backlight.Write(GpioPinValue.High);
        var display = DisplayController.GetDefault();

        var controllerSetting = new
            GHIElectronics.TinyCLR.Devices.Display.ParallelDisplayControllerSettings
        {
            Width = 480,
            Height = 272,
            DataFormat = GHIElectronics.TinyCLR.Devices.Display.DisplayDataFormat.Rgb565,
            PixelClockRate = 10000000,
            PixelPolarity = false,
            DataEnablePolarity = false,
            DataEnableIsFixed = false,
            HorizontalFrontPorch = 2,
            HorizontalBackPorch = 2,
            HorizontalSyncPulseWidth = 41,
            HorizontalSyncPolarity = false,
            VerticalFrontPorch = 2,
            VerticalBackPorch = 2,
            VerticalSyncPulseWidth = 10,
            VerticalSyncPolarity = false,
        };

        display.SetConfiguration(controllerSetting);
        display.Enable();
        
        app = new Program(display);
        app.Run(Program.CreateWindow(display));
    }

    private static Window CreateWindow(DisplayController display)
    {
        var window = new Window
        {
            Height = (int)display.ActiveConfiguration.Height,
            Width = (int)display.ActiveConfiguration.Width
        };

        window.Background = new LinearGradientBrush
            (Colors.Blue, Colors.Teal, 0, 0, window.Width, window.Height);

        window.Visibility = Visibility.Visible;
        window.Child = Elements();

        return window;
    }

    private static UIElement Elements()
    {
        var font = new Font("GHIMono8x5", 8);
        var txt = new TextBox
        {
            Font = font,
            Text = "Hello World!",
            HorizontalAlignment = HorizontalAlignment.Center,
            VerticalAlignment = VerticalAlignment.Center
        };

        return txt;
    }
}

Here is the Exception

[Default DispatcherException Handler] Exception caught: System.ArgumentException
#### Exception System.ArgumentException - 0xfd000000 (1) ####
#### Message: 
#### System.Drawing.Font::ComputeExtent [IP: 0000] ####
#### System.Drawing.Font::ComputeExtent [IP: 000c] ####
#### GHIElectronics.TinyCLR.UI.Controls.TextBox::MeasureOverride [IP: 000e] ####
#### GHIElectronics.TinyCLR.UI.UIElement::Measure [IP: 010d] ####
#### GHIElectronics.TinyCLR.UI.Controls.Panel::MeasureOverride [IP: 0020] ####
#### GHIElectronics.TinyCLR.UI.UIElement::Measure [IP: 010d] ####
#### GHIElectronics.TinyCLR.UI.Window::MeasureOverride [IP: 001b] ####
#### GHIElectronics.TinyCLR.UI.UIElement::Measure [IP: 00e8] ####
#### GHIElectronics.TinyCLR.UI.Controls.Canvas::MeasureOverride [IP: 001e] ####
#### GHIElectronics.TinyCLR.UI.WindowManager::MeasureOverride [IP: 0009] ####
#### GHIElectronics.TinyCLR.UI.UIElement::Measure [IP: 010d] ####
#### GHIElectronics.TinyCLR.UI.LayoutManager::UpdateLayout [IP: 0090] ####
#### GHIElectronics.TinyCLR.UI.LayoutManager::UpdateLayoutCallback [IP: 0004] ####
#### GHIElectronics.TinyCLR.UI.Media.MediaContext+InvokeOnRenderCallback::DoWork [IP: 000b] ####
#### GHIElectronics.TinyCLR.UI.Threading.Dispatcher::PushFrameImpl [IP: 0054] ####
#### GHIElectronics.TinyCLR.UI.Threading.Dispatcher::PushFrame [IP: 0018] ####
#### GHIElectronics.TinyCLR.UI.Threading.Dispatcher::Run [IP: 0006] ####
#### GHIElectronics.TinyCLR.UI.Application::Run [IP: 0066] ####
#### UserInterfaceExample.Program::Main [IP: 00a2] ####

if face problem by using this : var font = new Font(“GHIMono8x5”, 8);

so after i created resource file and used font from resources seems internal fonts is missing

I think we removed the internal font. @Dat_Tran can you confirm that there is no internal font?

no, it is gone.

@Gus_Issa , @Dat_Tran

can you share all GHI fonts to download from web ,
to be able we to include it on resource file .

We do not own any fonts but the samples we are uploading have fonts built in. This should make it easier for everyone to get started.

1 Like