我承认,我一直在学习棱镜,他们的一些观念对我来说并不清楚。我遇到了一些问题,我不知道如何解决它。 我必须构建creaotr的配置,我在几个视图上例如:profile,完成后,用信用卡查看,然后查看地址然后一些配置附加的东西。 其中一些是necesery喜欢的个人资料和地址。如果我们没有个人资料,我们不能去解决。他们中的一些人不像信用卡这样的nessecery。
我的公司希望使用一个常见的TabControl和一个常见的tabItem来完成它。在这个tabItem里面我必须显示每个视图。 我必须在点击按钮后更改View" Next"或"想念"。我也有PreviousStep。 我的问题是如何在一些ORDER中存储许多View。
到目前为止: 我有课
GeneralBaseViewModel : BindableBase, INavigationAware
这是抽象类,是每个班级的共同点。
我有GeneralHost.xaml只有
mvvm:RegionManager.RegionName="MainTabControlRegion"
作为telerik:RadTabControl(所以它正常的TabControl)。每个视图都有tabControl常用的类。
在应该用第一个视图打开这些选项卡的菜单中,我实现了添加
的NavigateOnif (viewType == typeof(IConfiguration))
{
this.RegionManager.RequestNavigate(RegionNames.MainRegion, typeof(GeneralHost).FullName);
this.RegionManager.RequestNavigate(RegionNames.MainTabControlRegion, viewType.FullName);
return;
}
MainTabControlRegion内部我想添加View - >所以我创建了MyProfileViewModel(它实现了IConfiguration)和MyProfile,它们看起来像:
<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:lang="clr-namespace:LanguageResources.Properties;assembly=LanguageResources"
xmlns:mvvm="http://prismlibrary.com/"
xmlns:mainRegionItems="clr-namespace:App.MainRegionItems"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
xmlns:converters="clr-namespace:Shared.Converters;assembly=Shared"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:enumerators="clr-namespace:AppManager.Models.ComplexTypes.Enumerators;assembly=AppManager.Models"
Style="{DynamicResource ControlDefaultStyle}"
d:DataContext="{d:DesignInstance mainRegionItems:MyProfileViewModel, IsDesignTimeCreatable=True}"
x:Class="App.MainRegionItems.ConfigurationOfProfile" mc:Ignorable="d" mvvm:ViewModelLocator.AutoWireViewModel="True" d:DesignHeight="800" d:DesignWidth="800" >
<i:Interaction.Triggers>
<i:EventTrigger EventName="Loaded">
<i:InvokeCommandAction Command="{Binding LoadDataCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<telerik:RadBusyIndicator BusyContent="{x:Static lang:Resources.PleadeWait}" IsBusy="{Binding IsBusy}">
<Grid Background="White" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<GroupBox Grid.Column="0" Grid.Row="0" Header="{x:Static lang:Resources.AddressSender}"
HorizontalAlignment="Left" VerticalAlignment="Top" Height="307" Width="400">
<Grid>
<Grid.Resources>
<Style TargetType="{x:Type TextBox}">
<Setter Property="Margin" Value="5" />
</Style>
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<Label Grid.Row="0" Grid.Column="0" Content="{x:Static lang:Resources.Name}" />
<TextBox Grid.Row="0" Grid.Column="1" Text="{Binding ModifiedInstance.DefaultSendingAddress.CompanyName,ValidatesOnDataErrors=True, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<Label Grid.Row="1" Grid.Column="0"
Content="{x:Static lang:Resources.AdditionalName}" />
<TextBox Grid.Row="1" Grid.Column="1"
Text="{Binding ModifiedInstance.DefaultSendingAddress.AdditionalName,ValidatesOnDataErrors=True,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</Grid>
</GroupBox>
<Menu Grid.Column="1" Grid.Row="1" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="10" Height="23" >
<MenuItem Style="{DynamicResource MenuItemStyle}" Command="{Binding SaveDataCommand}"
Header="{x:Static lang:Resources.SaveData}">
<MenuItem.Icon>
<Image Source="/App;component/Icons/Zapisz.ico" Height="25" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Style="{DynamicResource MenuItemStyle}" Command="{Binding NextStepCommand}"
Header="{x:Static lang:Resources.NextStep}">
<MenuItem.Icon>
<Image Source="/App;component/Icons/Zapisz.ico" Height="25" />
</MenuItem.Icon>
</MenuItem>
<MenuItem Style="{DynamicResource MenuItemStyle}" Command="{Binding PreviousStepCommand}"
Header="{x:Static lang:Resources.PreviousStep}">
<MenuItem.Icon>
<Image Source="/App;component/Icons/Zapisz.ico" Height="25" />
</MenuItem.Icon>
</MenuItem>
</Menu>
</Grid>
</telerik:RadBusyIndicator>
</UserControl>
我的虚拟机:
public class ConfigurationOfProfileViewModel : GeneralBaseViewModel, IConfiguration
{
/// <summary>
/// The report title.
/// </summary>
protected override string GeneralDetailTitle => "Configuration";
public override void OnNavigatedTo(NavigationContext navigationContext)
{
this.GetConfigurationData();
}
/// <summary>
/// The get report data.
/// </summary>
public void GetConfigurationData()
{
this.LoadingOn();
this.SetHeaderTitle();
this.LoadData();
this.LoadingOff();
}
public int indexOrder = 0;
private ICommand saveDataCommand;
public ICommand SaveDataCommand => saveDataCommand ?? (saveDataCommand = new DelegateCommand(SaveData));
private ICommand loadDataCommand;
public ICommand LoadDataCommand => loadDataCommand ?? (loadDataCommand = new DelegateCommand(LoadData));
private ICommand nextStepCommand;
public ICommand NextStepCommand => nextStepCommand ?? (nextStepCommand = new DelegateCommand(NextStep));
private ICommand previousStepCommand;
public ICommand PreviousStepCommand => previousStepCommand ?? (previousStepCommand = new DelegateCommand(LoadData));
private Profile modifiedInstance;
public Profile ModifiedInstance
{
get
{
return this.modifiedInstance;
}
private set
{
this.SetProperty(ref this.modifiedInstance, value);
this.OnPropertyChanged(() => this.ModifiedInstance);
}
}
private void LoadData()
{
var repProfile = new ProfileRepository();
Task<Profile> taskProfile = repProfile.GetPodmiot();
this.ModifiedInstance = taskProfile.Result;
if (this.ModifiedInstance == null)
{
this.ModifiedInstance = new Profile();
}
if (this.ModifiedInstance.ProfileData == null)
{
this.ModifiedInstance.ProfileData = new Address();
}
this.OnPropertyChanged(() => this.ModifiedInstance);
}
public async void SaveData()
{
this.LoadingOn();
try
{
var repProfile = new ProfileRepository();
var taskProfiles = repProfile.GetAll();
var profiles = taskProfiles.Result;
if (profiles.Any())
{
await repProfile.Modify(this.ModifiedInstance);
}
else
{
await repProfile.Add(this.ModifiedInstance, this.currentlyLoggedUser);
}
UserMessageBox.ShowError(Resources.Save, Resources.SaveSucceed, MessageBoxType.Information);
this.LoadingOff();
}
catch (Exception e)
{
throw e;
}
}
public async void NextStep()
{
try
{
this.SaveData();
}
catch (Exception ex)
{
UserMessageBox.ShowError(Resources.SaveFailed, ex.Message);
}
}
}
我还创建了其他视图,如CreditCardConfiguration和VM(实现IConfiguration),SenderAddress,ReceiverAddress等。每个VM都有属性indexOrder(int)。
我的问题是如何准备NextStepCommand,它应该改变MainTabControlRegion的内容。视图必须按特定顺序提供。 如果我完成了indexOrder = 0的配置文件,我可以使用indexOrder = 1转到下一个View。现在执行NextStepCommand后我只保存了配置文件。 如何重新加载RegionNames.MainTabControlRegion的内容?以及如何实现这些视图的排序?
感谢您的帮助。
答案 0 :(得分:0)
在NextStep方法中使用IRegionManager.RequestNavigate导航到下一个视图。如果执行此操作,您将自动获得以前的功能。您应该在文档http://prismlibrary.readthedocs.io/en/latest/WPF/08-Navigation/#view-based-navigation
中阅读Prism的导航功能