我不知道为什么Frame.Navigate和NavigationService不起作用。

这是我的以下代码,
MainPage.xaml:

<Grid>
    <ContentControl Content="{Binding CurrentViewModel}" />

    <Button
        Command="{Binding ConnexionViewCommand}"
        x:Name="Connexion_button"
        HorizontalAlignment="Left"
        Margin="90,308,0,0"
        Content="Login"
        VerticalAlignment="Top"
        Width="282"/>
    <Button
        Command="{Binding InscriptionViewCommand}"
        x:Name="Create_account"
        HorizontalAlignment="Left"
        Margin="90,446,0,0"
        Content="Create Account"
        VerticalAlignment="Top"
        Width="282"/>
</Grid>

MainViewModel.cs
public class MainViewModel : ViewModelBase
{
    private ViewModelBase _currentViewModel;

    readonly static ConnexionViewModel _ConnexionViewModel = new ConnexionViewModel();
    readonly static InscriptionViewModel _InscriptionViewModel = new InscriptionViewModel();
    readonly static MainPageViewModel _MainPageViewModel = new MainPageViewModel();


    public ViewModelBase CurrentViewModel
    {
        get
        {
            return _currentViewModel;
        }
        set
        {
            if (_currentViewModel == value)
                return;
            _currentViewModel = value;
            RaisePropertyChanged("CurrentViewModel");
        }
    }
    public ICommand ConnexionViewCommand { get; private set; }
    public ICommand InscriptionViewCommand { get; private set; }

    public MainViewModel()
    {
        CurrentViewModel = MainViewModel._MainPageViewModel;
        ConnexionViewCommand =  new RelayCommand(() => ExecuteConnexionViewCommand());
        InscriptionViewCommand = new RelayCommand(() => ExecuteInscriptionViewCommand());
    }

    private void ExecuteConnexionViewCommand()
    {
        Frame.Navigate(typeof(ConnexionView));
        NavigationService.Navigate(new Uri("/ConnexionView.xaml", UriKind.Relative));
        MessageBox.Show("CONNEXION");
    }

    private void ExecuteInscriptionViewCommand()
    {
        Frame.Navigate(typeof(InscriptView));
        NavigationService.Navigate(new Uri("/InscriptionView.xaml", UriKind.Relative));
        MessageBox.Show("REGISTER");
    }

我的Frame.navigate出现以下错误:无法将System.String转换为System.Uri。

对于我的NavigationService.Navigate:该属性需要一个对象引用。方法或非静态字段“NavigationService.Navigate(Uri)

谢谢你的帮助。

最佳答案

您不能将Frame.nagivate和NavigationService.Navigate混合在一起。

关于c# - Frame.navigate和NagivationService不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33105386/

10-09 09:08