Почему я не могу нажать кнопку «Образцы», и она возвращает меня к пользовательскому элементу управления, который я хочу, после второго нажатия кнопки.
Вот настройка приложения :
ShellView XAML Сводка: Когда пользователь нажимает на элемент дерева, он направляет их в пользовательский элемент управления. Для этого примера мы можем сосредоточиться на кнопке «Образцы». При нажатии на «Образцы» он направляет пользователя к представлению «WIOASamples», которое заполняется в области «WIOARegion», расположенной в ShellView xaml. Это представление «WIOASamples» имеет представление списка, которое при щелчке по строке направляется в представление сведений под названием «WIOADataEntry», которое отображается через область «WIOARegion», расположенную в xaml ShellView.
Проблема: когда пользователь находится в подробном представлении и пытается нажать кнопку «Образцы», он возвращается к пользовательскому элементу управления Listview. Тем не менее, если щелкнуть запись в представлении списка и перейти в пользовательский элемент управления «Подробности» и попытаться нажать кнопку «Образцы», она не вернется назад. Есть что-то, что я делаю неправильно? См. XAML / код ниже
Shell View XAML: область фокуса будет областью содержимого и элементом дерева примеров.
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200"/>
<ColumnDefinition Width="211*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<ContentControl MinHeight="20" Visibility="Collapsed" prism:RegionManager.RegionName="WIOARibbon" Grid.ColumnSpan="2" Margin="0"/>
<Grid Background="WhiteSmoke" Grid.Row="1" Grid.Column="0" Margin="0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock Text="SRM DASHBOARD" Foreground="DarkGray" Margin="10" FontSize="20" />
<StackPanel Grid.Row="1" Margin="5" Orientation="Vertical">
<TextBlock Visibility="Collapsed" Text="Board" VerticalAlignment="Center" Margin="5 0"/>
<ComboBox Width="150" SelectedIndex="0" DisplayMemberPath="board_name" ItemsSource="{Binding lstBoards}" Text="{Binding BoardNumber, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" >
</ComboBox>
<TextBlock HorizontalAlignment="Center" Padding="5" Margin="5 0" VerticalAlignment="Center">
<Hyperlink Command="{Binding SendMessageCommand}">Change</Hyperlink>
</TextBlock>
</StackPanel>
<ScrollViewer VerticalContentAlignment="Stretch" Grid.Row="2">
<TreeView Name="treeView" PreviewMouseWheel="treeView_PreviewMouseWheel" VerticalContentAlignment="Stretch" ScrollViewer.VerticalScrollBarVisibility="Auto" >
<TreeViewItem IsExpanded="True">
<TreeViewItem.Header>
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Margin="5" VerticalAlignment="Center" Kind="Database"/>
<TextBlock VerticalAlignment="Center" Text="WIOA TAA Samples"/>
</StackPanel>
</TreeViewItem.Header>
<TreeViewItem >
<TreeViewItem.Header>
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Margin="5" VerticalAlignment="Center" Kind="Layers"/>
<TextBlock VerticalAlignment="Center" Text="Samples"/>
</StackPanel>
</TreeViewItem.Header>
<i:Interaction.Triggers>
<i:EventTrigger EventName="Selected">
<i:InvokeCommandAction Command="{Binding WIOASamplesCommand}" CommandParameter="{Binding ElementName=treeView, Path=SelectedItem}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</TreeViewItem>
<TreeViewItem >
<TreeViewItem.Header>
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Margin="5" VerticalAlignment="Center" Kind="ChartBar"/>
<TextBlock VerticalAlignment="Center" Text="Reports"/>
</StackPanel>
</TreeViewItem.Header>
<i:Interaction.Triggers>
<i:EventTrigger EventName="Selected">
<i:InvokeCommandAction Command="{Binding WIOAReportsCommand}" CommandParameter="{Binding ElementName=treeView, Path=SelectedItem}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</TreeViewItem>
<TreeViewItem >
<TreeViewItem.Header>
<StackPanel Orientation="Horizontal">
<materialDesign:PackIcon Margin="5" VerticalAlignment="Center" Kind="Edit"/>
<TextBlock VerticalAlignment="Center" Text="Element Editor"/>
</StackPanel>
</TreeViewItem.Header>
</TreeViewItem>
</TreeViewItem>
<TreeViewItem Header="Importer" IsExpanded="True">
<TreeViewItem Header="WIOA TAA Import" />
<TreeViewItem Header="BATS Import" />
</TreeViewItem>
</TreeView>
</ScrollViewer>
<!--<RadioButton IsChecked="True" Content="WIOA TAA Samples" FontSize="18" Foreground="#FF3E3E3E" Style="{StaticResource buttonstripe1}" Command="{Binding TestViewCommand}" />
<RadioButton Content="BATS" FontSize="18" Foreground="#FF3E3E3E" Style="{StaticResource buttonstripe1}" Command="{Binding BATSCommand}" />
<RadioButton Content="Importer" FontSize="18" Foreground="#FF3E3E3E" Style="{StaticResource buttonstripe1}" Command="{Binding ImporterCommand}" />-->
</Grid>
<ContentControl MinWidth="80" prism:RegionManager.RegionName="WIOARegion" Grid.Column="1" Grid.Row="1" Margin="0"/>
</Grid>
ShellView Code Behind
public class SRMShellViewModel : BindableBase, INavigationAware
{
IRegionManager _regionManager;
IRegionNavigationJournal _journal;
IEventAggregator _ea;
#region Commands
public DelegateCommand TestViewCommand { get; set; }
public DelegateCommand WIOASamplesCommand { get; set; }
public DelegateCommand WIOAReportsCommand { get; set; }
public DelegateCommand WIOAEditorCommand { get; set; }
public DelegateCommand BATSCommand { get; set; }
public DelegateCommand GoBackCommand { get; set; }
public DelegateCommand ImporterCommand { get; set; }
#endregion
public SRMShellViewModel(IRegionManager regionManager, IEventAggregator ea)
{
_regionManager = regionManager;
_ea = ea;
TestViewCommand = new DelegateCommand(NavigateToTestView);
BATSCommand = new DelegateCommand(NavigateToBAMView);
ImporterCommand = new DelegateCommand(NavigateToImporter);
WIOAEditorCommand = new DelegateCommand(NavigateToWIOAEditor);
WIOASamplesCommand = new DelegateCommand(NavigateToWIOASamples);
WIOAReportsCommand = new DelegateCommand(NavigateToWIOAReports);
GoBackCommand = new DelegateCommand(GoBack);
}
private void NavigateToWIOASamples()
{
MessageBox.Show("YOU CLICKED ME");
_regionManager.RequestNavigate("WIOARegion", "WIOASamples");
_regionManager.RequestNavigate("WIOARibbon", "WIOARibbon");
}
private void NavigateToWIOAReports()
{
_regionManager.RequestNavigate("WIOARegion", "WIOAReports");
_regionManager.RequestNavigate("WIOARibbon", "WIOARibbon");
}
private void NavigateToWIOAEditor()
{
_regionManager.RequestNavigate("WIOARegion", "WIOAImportLogin");
_regionManager.RequestNavigate("WIOARibbon", "WIOARibbon");
}
private void NavigateToTestView()
{
_regionManager.RequestNavigate("WIOARegion", "WIOASampleIndex");
_regionManager.RequestNavigate("WIOARibbon", "WIOARibbon");
}
private void NavigateToImporter()
{
_regionManager.RequestNavigate("WIOARegion", "ViewA");
}
private void NavigateToBAMView()
{
_regionManager.RequestNavigate("WIOARegion", "BatsIndex");
_regionManager.RequestNavigate("WIOARibbon", "BATSRibbon");
}
#region INavigationAware
public void OnNavigatedTo(NavigationContext navigationContext)
{
_journal = navigationContext.NavigationService.Journal;
}
public bool IsNavigationTarget(NavigationContext navigationContext)
{
return true;
}
public void OnNavigatedFrom(NavigationContext navigationContext)
{
// MessageBox.Show("YOU are navigating from ME");
_journal = navigationContext.NavigationService.Journal;
var q = navigationContext.NavigationService.Journal.CurrentEntry;
}
}
Примеры XAML
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Visibility="Collapsed" Grid.RowSpan="2" Orientation="Vertical" Margin="0,0,738,0">
<Button Visibility="Collapsed" Content="Adults" HorizontalContentAlignment="Left" Command="{Binding AdultCommand}" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="#FF3E3E3E" />
<Button Visibility="Collapsed" Margin="0 5" HorizontalContentAlignment="Left" Content="Youth" Command="{Binding YouthCommand}" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="#FF3E3E3E" />
<Button Visibility="Collapsed" Margin="0 5" HorizontalContentAlignment="Left" Content="DW" Command="{Binding DWCommand}" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="#FF3E3E3E" />
<Button Visibility="Collapsed" HorizontalContentAlignment="Stretch" VerticalAlignment="Stretch" Margin="10" Background="{x:Null}" BorderBrush="#FF646464" >
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackPanel Orientation="Vertical">
<materialDesign:PackIcon Foreground="#FF646464" Kind="PersonChild" Height="51" Width="56"/>
<TextBlock Text="WIOA NDW" Foreground="#FF646464" FontSize="16"/>
</StackPanel>
<TextBlock Text="8" HorizontalAlignment="Right" Foreground="#FF646464" FontSize="36" Grid.Column="1"/>
</Grid>
</Button>
<Button Visibility="Collapsed" Content="TAA" Margin="0 5" HorizontalContentAlignment="Left" Command="{Binding TAACommand}" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="#FF3E3E3E" />
</StackPanel>
<Button Content="Export" Grid.Row="0" Margin="0,10,10,10" HorizontalAlignment="Right"/>
<TextBlock Visibility="Collapsed" Text="{Binding BoardNumber, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
<StackPanel Orientation="Horizontal">
<TextBlock VerticalAlignment="Center" Margin="5" Text="Program" Opacity=".56"/>
<ComboBox Margin="5" Grid.Column="1" MinWidth="200" SelectedIndex="0" Text="{Binding ProgramName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
<ComboBoxItem Content="WIOA Adult"/>
<ComboBoxItem Content="WIOA Youth"/>
<ComboBoxItem Content="WIOA Dislocated Worker"/>
<ComboBoxItem Content="Hurricane Harvey NDWG"/>
<ComboBoxItem Content="Trade Adjustment Act "/>
</ComboBox>
</StackPanel>
<ListView Grid.Row="1" Margin="10" Name="lvUsers" ItemsSource="{Binding lstOfSamples, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
<ListView.View>
<GridView>
<GridViewColumn Header="First Name" Width="150" DisplayMemberBinding="{Binding first_name}" />
<GridViewColumn Header="Last Name" Width="150" DisplayMemberBinding="{Binding last_name}" />
<GridViewColumn Header="Customer ID" Width="150" DisplayMemberBinding="{Binding customer_id}" />
<GridViewColumn Header="Board" Width="100" DisplayMemberBinding="{Binding wda_no, FallbackValue=Incomplete}" />
<GridViewColumn Header="" Width="150">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Button Content="View" Command="{Binding PersonSelectedCommand}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
<ListBox Visibility="Collapsed" Margin="160,10,10,10" ItemsSource="{Binding lstOfSamples, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock VerticalAlignment="Center" Text="{Binding first_name}"/>
<TextBlock VerticalAlignment="Center" Text=" "/>
<TextBlock VerticalAlignment="Center" Text="{Binding last_name}"/>
<TextBlock VerticalAlignment="Center" Text=" "/>
<TextBlock VerticalAlignment="Center" Text="{Binding customer_id}"/>
<Button Content="View" Margin="10"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
Образцы C#
public class WIOASamplesViewModel : BindableBase, INavigationAware
{
IEventAggregator _ea;
IRegionManager _regionManager;
IRegionNavigationJournal _journal;
private int _board_number;
public int BoardNumber
{
get { return _board_number; }
set { SetProperty(ref _board_number, value); }
}
private string _programName;
public string ProgramName
{
get { return _programName; }
set
{
SetProperty(ref _programName, value);
lstOfSamples = GetSampleData(ProgramName, Convert.ToInt32(BoardNumber));
}
}
private wioa_sample_data_view_model _wioa_sample_data_view_model;
public wioa_sample_data_view_model wioa_sample_data_view_model
{
get { return _wioa_sample_data_view_model; }
set { SetProperty(ref _wioa_sample_data_view_model, value); }
}
private ObservableCollection<WIOAListViewModel> _lstOfSamples;
public ObservableCollection<WIOAListViewModel> lstOfSamples
{
get { return _lstOfSamples; }
set { SetProperty(ref _lstOfSamples, value); }
}
public WIOASamplesViewModel(IEventAggregator ea, IRegionManager regionManager)
{
_regionManager = regionManager;
_ea = ea;
_ea.GetEvent<MessageSentEvent>().Subscribe(MessageReceived);
// lstOfSamples = GetSampleData("WIOA Adult", 1);
}
private void MessageReceived(string message)
{
message = message.Remove(2);
lstOfSamples = GetSampleData(ProgramName, Convert.ToInt32(message));
BoardNumber = Convert.ToInt32(message);
// Messages.Add(message);
}
ObservableCollection<WIOAListViewModel> GetSampleData(string program, int boardNumber)
{
//ProgramName = program;
ObservableCollection<WIOAListViewModel> lst = new ObservableCollection<WIOAListViewModel>();
var qry = DatabaseHelper.audit_sample_repo.GetSampleByProgram(program, boardNumber);
// var qry = DatabaseHelper.audit_sample_repo.GetAll();
foreach (var record in qry)
{
WIOAListViewModel model = new WIOAListViewModel(_regionManager);
model.id = record.id;
model.first_name = record.first_name;
model.last_name = record.last_name;
model.customer_id = record.customer_id;
model.wda_no = record.wda_no;
model.program = record.program;
lst.Add(model);
}
return lst;
}
public void OnNavigatedTo(NavigationContext navigationContext)
{
_journal = navigationContext.NavigationService.Journal;
if (BoardNumber == 0)
{
BoardNumber = 1;
lstOfSamples = GetSampleData(ProgramName, BoardNumber);
}
}
public bool IsNavigationTarget(NavigationContext navigationContext)
{
return true;
//throw new NotImplementedException();
}
public void OnNavigatedFrom(NavigationContext navigationContext)
{
_journal = navigationContext.NavigationService.Journal;
}
}
Для пользователя, чтобы перейти в представление сведений для выбранной строки, это делается путем привязки команды кнопки к модели. Код ниже:
public class WIOAListViewModel : BindableBase, INavigationAware
{
IRegionManager _regionManager;
IRegionNavigationJournal _journal;
private int _id;
public int id
{
get { return _id; }
set { SetProperty(ref _id, value); }
}
private int _wda_no;
public int wda_no
{
get { return _wda_no; }
set { _wda_no = value; }
}
private string _first_name;
public string first_name
{
get { return _first_name; }
set { SetProperty(ref _first_name, value); }
}
private string _last_name;
public string last_name
{
get { return _last_name; }
set { SetProperty(ref _last_name, value); }
}
private int _customer_id;
public int customer_id
{
get { return _customer_id; }
set { SetProperty(ref _customer_id, value); }
}
private string _program;
public string program
{
get { return _program; }
set { SetProperty(ref _program, value); }
}
public WIOAListViewModel(IRegionManager regionManager)
{
_regionManager = regionManager;
PersonSelectedCommand = new DelegateCommand<WIOAListViewModel>(PersonSelected);
}
public DelegateCommand<WIOAListViewModel> PersonSelectedCommand { get; private set; }
private void PersonSelected(WIOAListViewModel person)
{
var parameters = new NavigationParameters();
parameters.Add("person", this);
if (this != null)
_regionManager.RequestNavigate("WIOARegion", "WIOADataEntry", parameters);
}
public void OnNavigatedTo(NavigationContext navigationContext)
{
_journal = navigationContext.NavigationService.Journal;
PersonSelectedCommand.RaiseCanExecuteChanged();
}
public bool IsNavigationTarget(NavigationContext navigationContext)
{
return true;
}
public void OnNavigatedFrom(NavigationContext navigationContext)
{
// throw new NotImplementedException();
}
}