wildREA
wildREA
CC#
Created by wildREA on 2/11/2025 in #help
XAML property issues
No description
1 replies
CC#
Created by wildREA on 1/30/2025 in #help
Manually Showing MainWindow.xaml In App.xaml.cs (Dependency Injection)
Hey! My code is supposed to manually show MainWindow.xaml, but it doesn't if I remove StartupUri="MainWindow.xaml" and I get the error that is listed with details below with it. Without it, I get no error, so it must be my logic. The way I wrote it is because of dependency injection for AppLanguageServices. App.xaml
<Application x:Class="computerComponentsTracker.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Application x:Class="computerComponentsTracker.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
App.xaml.cs
private static IServiceProvider? ServiceProvider;

protected override void OnStartup(StartupEventArgs e)
{
var serviceCollection = new ServiceCollection();

// Register services
serviceCollection.AddSingleton<IAppLanguageServices, AppLanguageServices>();
serviceCollection.AddTransient<ComponentUsage>();
serviceCollection.AddTransient<MainWindow>();
serviceCollection.AddTransient<Settings>();

// Build service provider
ServiceProvider = serviceCollection.BuildServiceProvider();

// Manually create and show MainWindow
var mainWindow = ServiceProvider.GetRequiredService<MainWindow>();
mainWindow?.Show();

base.OnStartup(e);
}
private static IServiceProvider? ServiceProvider;

protected override void OnStartup(StartupEventArgs e)
{
var serviceCollection = new ServiceCollection();

// Register services
serviceCollection.AddSingleton<IAppLanguageServices, AppLanguageServices>();
serviceCollection.AddTransient<ComponentUsage>();
serviceCollection.AddTransient<MainWindow>();
serviceCollection.AddTransient<Settings>();

// Build service provider
ServiceProvider = serviceCollection.BuildServiceProvider();

// Manually create and show MainWindow
var mainWindow = ServiceProvider.GetRequiredService<MainWindow>();
mainWindow?.Show();

base.OnStartup(e);
}
148 replies
CC#
Created by wildREA on 1/24/2025 in #help
How to Correctly Reference a Method in App.xaml.cs
Hey, reviewer. The ChangeLanguage method should work, but referencing is a challenge at the moment, since I get the error 'App' does not contain a definition for 'ChangeLanguage' and no accessible extension method 'ChangeLanguage' accepting a first argument of type 'App' could be found (are you missing a using directive or an assembly reference?). The OnLanguageChanged method works until I add that reference for ((App)Application.Current).... How do I correctly reference to a method in App.xaml.cs? ---- Settings.xaml.cs
public partial class Settings : UserControl
{
public Settings()
{
InitializeComponent();
}

private void OnLanguageChanged(object sender, SelectionChangedEventArgs e)
{
string? selectedLanguage = ((ComboBoxItem?)e.AddedItems[0]).Tag.ToString();
Debug.WriteLine(selectedLanguage);
((App)Application.Current).ChangeLanguage(selectedLanguage);
}
}
}
public partial class Settings : UserControl
{
public Settings()
{
InitializeComponent();
}

private void OnLanguageChanged(object sender, SelectionChangedEventArgs e)
{
string? selectedLanguage = ((ComboBoxItem?)e.AddedItems[0]).Tag.ToString();
Debug.WriteLine(selectedLanguage);
((App)Application.Current).ChangeLanguage(selectedLanguage);
}
}
}
App.xaml.cs
public partial class App : Application
{
public void ChangeLanguage(string language)
{
public partial class App : Application
{
public void ChangeLanguage(string language)
{
8 replies
CC#
Created by wildREA on 1/22/2025 in #help
✅ Ways to Add Language Support (WPF)
I'm creating a hardware monitor software that will show statistics of (primarily internal) components. There is a monitor and a settings user control to switch between the two. There are two user controls for the controls themselves and then a window, which is MainWindow that serves as the median between these two. How would I go about switching languages dynamically in my XAML when a selected ComboBoxItem for a language is selected, which is applied upon clicking on the apply button? Like methods of implementation.
3 replies
CC#
Created by wildREA on 12/12/2022 in #help
❔ ✅ [RESOLVED] Unavailable Start without Debugging
43 replies