Hello Stackoverflow Community.
I just started learning Avalonia and i’m wondering how to create a button that reroutes me from a view to another.
I have the first view titled ValueSelectionPageView and I want to add a button to it that reroutes me to view titled TextPageView
Code for ValueSelectionPageView.axaml:
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="AvaloniaApplication1.Views.ValueSelectionPageView"
xmlns:vm="using:AvaloniaApplication1.ViewModels"
x:DataType="vm:ValueSelectionPageViewModel"
>
</UserControl>
Code for TextPageView.axaml:
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="AvaloniaApplication1.Views.TextPageView"
xmlns:vm="using:AvaloniaApplication1.ViewModels"
x:DataType="vm:TextPageViewModel"
>
<StackPanel Spacing="10">
<StackPanel.Styles>
<Style Selector="TextBlock">
<Setter Property="Foreground" Value="White"></Setter>
<Setter Property="HorizontalAlignment" Value="Center"></Setter>
</Style>
</StackPanel.Styles>
<TextBlock>Hello and Welcome to the text page you can choose the border width below</TextBlock>
<TextBox Width="150" Watermark="Enter something" Text="{Binding ThicknessValue}"></TextBox>
<Button HorizontalAlignment="Center" Command="{Binding ChangeTextCommand}"> CLICK ME</Button>
<Border Margin="0,50,0,0" Width="200" Background="{DynamicResource SystemAccentColorDark1}" BorderBrush="{DynamicResource SystemAccentColor}" BorderThickness="{Binding DefaultThickness}" CornerRadius="8" Padding="16">
<TextBlock>Border</TextBlock>
</Border>
</StackPanel>
Code for ValueSelectionPageViewModel.cs:
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
namespace AvaloniaApplication1.ViewModels;
public class ValueSelectionPageViewModel : ViewModelBase
{
}
Code for TextPageViewModel.cs:
using System;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
namespace AvaloniaApplication1.ViewModels;
public partial class TextPageViewModel : ViewModelBase
{
[ObservableProperty]
private string _thicknessValue = "";
[ObservableProperty]
private string _defaultThickness = "7";
[RelayCommand]
private void ChangeText()
{
DefaultThickness = ThicknessValue;
}
}
I hope my description is clear, kindly assist me on the topic.
Thanks.