csharpc-sharpdotnetxamlavaloniauicross-platformcross-platform-xamlavaloniaguimulti-platformuser-interfacedotnetcore
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
2.9 KiB
84 lines
2.9 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Avalonia;
|
|
using Avalonia.Controls;
|
|
using Avalonia.Interactivity;
|
|
using Avalonia.Markup.Xaml;
|
|
|
|
namespace IntegrationTestApp
|
|
{
|
|
public class MainWindow : Window
|
|
{
|
|
private int _repeatButtonClickCount = 0;
|
|
private bool _repeatButtonClickHandlerAdded = false;
|
|
public MainWindow()
|
|
{
|
|
InitializeComponent();
|
|
InitializeViewMenu();
|
|
this.AttachDevTools();
|
|
AddHandler(Button.ClickEvent, OnButtonClick);
|
|
var buttons = this.Find<TabItem>("buttons");
|
|
buttons!.GetObservable(TabItem.IsSelectedProperty).Subscribe(x =>
|
|
{
|
|
if (x == true && _repeatButtonClickHandlerAdded == false)
|
|
{
|
|
this.Find<RepeatButton>("RepeatButton")!.Click += (a, e) =>
|
|
{
|
|
_repeatButtonClickCount++;
|
|
var textBlock = this.FindControl<TextBlock>("RepeatButtonTextBlock");
|
|
textBlock.Text = $"Repeat Button: {_repeatButtonClickCount}";
|
|
};
|
|
_repeatButtonClickHandlerAdded = true;
|
|
}
|
|
});
|
|
ListBoxItems = Enumerable.Range(0, 100).Select(x => "Item " + x).ToList();
|
|
DataContext = this;
|
|
}
|
|
|
|
|
|
public List<string> ListBoxItems { get; }
|
|
|
|
private void InitializeComponent()
|
|
{
|
|
AvaloniaXamlLoader.Load(this);
|
|
}
|
|
|
|
private void InitializeViewMenu()
|
|
{
|
|
var mainTabs = this.FindControl<TabControl>("MainTabs");
|
|
var viewMenu = (NativeMenuItem)NativeMenu.GetMenu(this).Items[1];
|
|
|
|
foreach (TabItem tabItem in mainTabs.Items)
|
|
{
|
|
var menuItem = new NativeMenuItem
|
|
{
|
|
Header = (string)tabItem.Header!,
|
|
IsChecked = tabItem.IsSelected,
|
|
ToggleType = NativeMenuItemToggleType.Radio,
|
|
};
|
|
|
|
menuItem.Click += (s, e) => tabItem.IsSelected = true;
|
|
viewMenu.Menu.Items.Add(menuItem);
|
|
}
|
|
}
|
|
|
|
private void MenuClicked(object? sender, RoutedEventArgs e)
|
|
{
|
|
var clickedMenuItemTextBlock = this.FindControl<TextBlock>("ClickedMenuItem");
|
|
clickedMenuItemTextBlock.Text = ((MenuItem)sender!).Header.ToString();
|
|
}
|
|
|
|
private void OnButtonClick(object? sender, RoutedEventArgs e)
|
|
{
|
|
var source = e.Source as Button;
|
|
|
|
if (source?.Name == "ComboBoxSelectionClear")
|
|
this.FindControl<ComboBox>("BasicComboBox").SelectedIndex = -1;
|
|
if (source?.Name == "ComboBoxSelectFirst")
|
|
this.FindControl<ComboBox>("BasicComboBox").SelectedIndex = 0;
|
|
if (source?.Name == "ListBoxSelectionClear")
|
|
this.FindControl<ListBox>("BasicListBox").SelectedIndex = -1;
|
|
}
|
|
}
|
|
}
|
|
|