AvaloniaUI/Avalonia.Samples

TransitioningContentControl can not show the view

BenDerPan opened this issue · 2 comments

my project was created with the visual studio tempalte, support desktop ,android and web.

MainViewModel:

public class MainViewModel : ViewModelBase
{
    ViewModelBase _CurrentViewModel;

    public ViewModelBase CurrentViewModel
    {
        get { return _CurrentViewModel; }
        private set { this.RaiseAndSetIfChanged(ref _CurrentViewModel, value); }
    }

    public MainViewModel() 
    {
        _CurrentViewModel=new LoginViewModel();
    }
}

MainView.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"
             xmlns:vm="clr-namespace:App1.ViewModels"
             mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
			 x:CompileBindings="True"
             x:Class="App1.Views.MainView"
             x:DataType="vm:MainViewModel">
  <Design.DataContext>
    <!-- This only sets the DataContext for the previewer in an IDE,
         to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs) -->
    <vm:MainViewModel />
  </Design.DataContext>
	<Grid>
		<TransitioningContentControl Content="{Binding CurrentViewModel}"></TransitioningContentControl>
	</Grid>

</UserControl>

LoginViewModel:

public class LoginViewModel : ViewModelBase
    {
        public LoginViewModel() { }
    }

LoginView.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"
			 xmlns:vm="using:App1.ViewModels"
             mc:Ignorable="d" d:DesignWidth="1440" d:DesignHeight="900"
             x:Class="App1.Views.LoginView"
			 x:DataType="vm:LoginViewModel">
	<WrapPanel Background="White">
		<Image Source="/Assets/bg.png" Margin="5"></Image>
		<Grid RowDefinitions="*,auto,*" ColumnDefinitions="*,auto,*" VerticalAlignment="Center">
			<Grid Grid.Row="1" Grid.Column="1" Margin="5">
				<StackPanel Orientation="Vertical">
					<TextBlock Text="Login" HorizontalAlignment="Center" VerticalAlignment="Center" FontWeight="Bold"  FontSize="28" Foreground="#282C40"></TextBlock>
					<StackPanel Orientation="Vertical" VerticalAlignment="Center" Margin="5,20">
						<TextBlock Text="User" FontSize="14" Foreground="#80828E" VerticalAlignment="Center" Margin="5"></TextBlock>
						<TextBox Watermark="Your account" MinWidth="376" FontFamily="Source Han Sans CN" FontSize="14" Foreground="#333333" VerticalAlignment="Center" VerticalContentAlignment="Center"></TextBox>
					</StackPanel>

					<StackPanel Orientation="Vertical" VerticalAlignment="Center" Margin="5,5">
						<TextBlock Text="Password" FontSize="14" Foreground="#80828E" VerticalAlignment="Center" Margin="5"></TextBlock>
						<TextBox PasswordChar="*" Watermark="Your password" MinWidth="376" FontSize="14" Foreground="#333333" VerticalAlignment="Center" VerticalContentAlignment="Center"></TextBox>
					</StackPanel>
				</StackPanel> 
			</Grid>
		</Grid>
	</WrapPanel>
</UserControl>

when run it , the main window only show the full name of the view model. I hope it show the login view
image

any routing example with the visual studio tempaltes? it generated without ViewLocator.cs too.

fixed, we should add ViewLocator to App.axaml.