Skip to content

Latest commit

 

History

History
56 lines (41 loc) · 1.4 KB

wpf-winui.md

File metadata and controls

56 lines (41 loc) · 1.4 KB

Samples — WPF / WinUI

Minimal WPF sample that lists GameInput devices and refreshes on demand. The runnable project is in samples/GameInputSharp.Samples.Wpf.

Run

From the repository root:

dotnet run --project samples/GameInputSharp.Samples.Wpf/GameInputSharp.Samples.Wpf.csproj

Requirements

  • .NET 8, Windows
  • GameInput runtime on the machine

What it does

  • On load: Creates a GameInputManager and populates a list with GetDevices().
  • Refresh button: Re-enumerates and updates the list.
  • On close: Disposes the manager.

Pattern

Use the manager on the UI thread (or marshal from a background thread with Dispatcher.Invoke).

private void OnLoaded(object sender, RoutedEventArgs e)
{
    _manager = new GameInputManager();
    RefreshDevices();
}

private void RefreshDevices()
{
    var devices = _manager.GetDevices();
    foreach (var d in devices)
    {
        string type = d switch
        {
            GamepadDevice => "Gamepad",
            KeyboardDevice => "Keyboard",
            MouseDevice => "Mouse",
            _ => "Device"
        };
        DeviceList.Items.Add($"{type}: {d.DisplayName} — {d.DeviceId}");
    }
}

For callbacks or polling on a background thread, marshal results to the UI. See the Full usage guide and Compatibility.


Sample location: samples/GameInputSharp.Samples.Wpf/