2014-10-04 4 views
0

Catel을 사용하여 간단한 앱을 개발 중입니다. 이전에 ReactiveUI를 사용했고 Catel을 시작하는 데 약간의 문제가 있습니다. 나는 기본 MainWindow를 가지고있다. 거기에 몇 가지 버튼이있는 툴바가 있습니다. 단추를 선택하면 응용 프로그램의 아래쪽 창에 사용자가 선택한 것을 기준으로 사용자 정의 컨트롤이 표시됩니다. 지금까지 나는 그것의 목록 ​​뷰와 그 뒤에있는 뷰 모델을 가진 하나의 기본 뷰를 가지고있다. 단추를 선택하면 해당보기를 표시하는 방법을 알아내는 데 도움이 필요합니다. 도와 줘서 고마워. 여기까지 내가 지금까지 가지고있는 것이있다. 보시다시피 mainviewmodel의 'ExecutePlayersButtonCommand'가 실행되면 플레이어보기를 표시해야합니다. 나는 이것을 얻는 방법을 모르겠다. 나는 그것이 팝업에 올라 오도록 할 수있다. 그러나 그것은 내가 원하는 것이 아니다. reactui에서 나는 Router.Navigate 함수로 그것을 할 수있다. 여기 어떻게해야할지 모르겠다.Catel을 사용하여 뷰를 표시하는 방법

<catel:DataWindow xmlns:Controls="clr-namespace:FootballSim.Controls;assembly=FootballSim.Controls" 
        xmlns:RedfoxSoftwareCustomControls="clr-namespace:RedfoxSoftwareCustomControls;assembly=RedfoxSoftwareCustomControls" 
        x:Class="FootballSim.Views.MainWindow" 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:catel="http://catel.codeplex.com" 
        xmlns:views="clr-namespace:FootballSim.Views" 
        Style="{StaticResource {x:Type Window}}" 
        ShowInTaskbar="True" ResizeMode="CanResize" SizeToContent="Manual" 
        WindowStartupLocation="Manual" WindowState="Maximized" Icon="/FootballSim;component/redfox_software_48x48.ico"> 

    <!-- Resources --> 
    <catel:DataWindow.Resources> 
    </catel:DataWindow.Resources> 

    <!-- Content --> 
    <catel:StackGrid x:Name="LayoutRoot"> 
     <catel:StackGrid.RowDefinitions> 
      <RowDefinition Height="Auto" /> 
      <RowDefinition Height="Auto" /> 
     </catel:StackGrid.RowDefinitions> 
     <DockPanel> 
      <StackPanel DockPanel.Dock="Top"> 
       <Grid> 
        <Grid.RowDefinitions> 
         <RowDefinition Height="*" /> 
         <RowDefinition Height="50" /> 
         <RowDefinition Height="100*" /> 
        </Grid.RowDefinitions> 
        <RedfoxSoftwareCustomControls:WpfCustomApplicationMenuBar x:Name="CustomMenuBar" Grid.Row="0" /> 
        <StackPanel Grid.Row="1"> 
         <Button HorizontalAlignment="Left" Command="{Binding PlayersButtonCommand}" Background="Transparent"> 
          <StackPanel> 
           <Image Source="/FootballSim;component/Resources/People_white_48.png" Width="30"></Image> 
           <TextBlock Text="Players" Foreground="White" HorizontalAlignment="Center"/> 
          </StackPanel> 
         </Button> 
        </StackPanel> 
        <DockPanel LastChildFill="True" Grid.Row="2"> 
         <ContentControl Content="{Binding contentObject}" /> 
         <!--<views:PlayersView DataContext="{Binding PlayerProviders}" />--> 
        </DockPanel> 
       </Grid> 
      </StackPanel> 
     </DockPanel> 
    </catel:StackGrid> 
</catel:DataWindow> 


    using Catel.Windows; 
using FootballSim.Scripts; 
using FootballSim.Services; 
using FootballSim.ViewModels; 
using System; 
using System.ComponentModel; 
using Catel.MVVM.Views; 
using Catel.Windows.Data; 
using Catel.MVVM; 


namespace FootballSim.Views 
{ 
    public partial class MainWindow : DataWindow 
    { 
     private RedfoxMessage logger = new RedfoxMessage(); 
     private PopulateDatabase database = new PopulateDatabase(); 
     public MainWindow() : base(DataWindowMode.Custom) 
     { 
      try 
      { 
       InitializeComponent(); 

       logger.LogMessage("Starting application."); 

       CustomMenuBar.AboutButtonClickEvent += CustomMenuBar_AboutButtonClickEvent; 
      } 
      catch (Exception e) 
      { 
       RedfoxMessage.LogMessage(e, NLog.LogLevel.Error); 
      } 
     } 

     private void CustomMenuBar_AboutButtonClickEvent(object sender, System.EventArgs args) 
     { 
      (DataContext as IMainWindowViewModel).AboutButtonCommand.Execute(null); 
     } 
    } 
} 

    using Catel.Data; 
using Catel.IoC; 
using Catel.MVVM; 
using Catel.MVVM.Services; 
using FootballSim.Models; 
using FootballSim.Scripts; 
using FootballSim.Views; 
using System.Collections.Generic; 
using System.Windows; 


namespace FootballSim.ViewModels 
{ 
    public interface IMainWindowViewModel 
    { 
     Command PlayersButtonCommand { get; } 
     Command AboutButtonCommand { get; } 

     List<Player> PlayerProviders { get; } 
     Player SelectedPlayerProvider { get; } 
     object ContentObject { get; } 
    } 

    /// <summary> 
    /// MainWindow view model. 
    /// </summary> 
    public class MainWindowViewModel : ViewModelBase, IMainWindowViewModel 
    { 
     //private readonly IUIVisualizerService _uiVisualizerService; 
     private PopulateDatabase _populateDatabase; 

     public static readonly PropertyData PlayerProvidersProperty = RegisterProperty("PlayerProviders", typeof(List<Player>)); 
     public static readonly PropertyData SelectedPlayerProviderProperty = RegisterProperty("SelectedPlayerProvider", typeof(Player)); 

     public Command PlayersButtonCommand { get; private set; } 
     public Command AboutButtonCommand { get; private set; } 
     public object ContentObject { get; set; } 

     public MainWindowViewModel() : base() 
     { 
      //var dependencyResolver = this.GetDependencyResolver(); 
      //_uiVisualizerService = dependencyResolver.Resolve<IUIVisualizerService>(); 
      _populateDatabase = new PopulateDatabase(); 
      PlayerProviders = _populateDatabase.Players; 

      var pv = new PlayersView(); 
      pv.DataContext = PlayerProviders; 
      ContentObject = pv; 

      PlayersButtonCommand = new Command(ExecutePlayersButtonCommand); 
      AboutButtonCommand = new Command(ExecuteAboutButtonCommand); 
     } 

     private void ExecutePlayersButtonCommand() 
     { 
      PlayerProviders = _populateDatabase.Players; 
      MessageBox.Show("Players"); 
     } 

     private void ExecuteAboutButtonCommand() 
     { 
      var aboutView = new AboutView(); 
      aboutView.ShowDialog(); 
     } 

     public List<Player> PlayerProviders 
     { 
      get 
      { 
       return GetValue<List<Player>>(PlayerProvidersProperty); 
      } 
      set 
      { 
       SetValue(PlayerProvidersProperty, value); 
      } 
     } 

     public Player SelectedPlayerProvider 
     { 
      get 
      { 
       return GetValue<Player>(SelectedPlayerProviderProperty); 
      } 
      set 
      { 
       SetValue(SelectedPlayerProviderProperty, value); 
      } 
     } 

     //protected override void Initialize() 
     //{ 
     // SelectedPlayerProvider = PlayerProviders[0]; 
     //} 



     public override string Title { get { return "FootballSim"; } } 
    } 
} 

    <catel:UserControl x:Class="FootballSim.Views.PlayersView" 
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
        xmlns:catel="http://catel.codeplex.com" 
        xmlns:views="clr-namespace:FootballSim.Views" 
        xmlns:viewmodels="clr-namespace:FootballSim.ViewModels" 
        xmlns:models="clr-namespace:FootballSim.Models;assembly=FootballSim.Core"> 

    <!-- Resources --> 
    <UserControl.Resources> 
    </UserControl.Resources> 

    <!-- Content --> 
    <catel:StackGrid> 
     <catel:StackGrid.RowDefinitions> 
      <RowDefinition Height="Auto" /> 
      <RowDefinition Height="Auto" /> 
      <RowDefinition Height="Auto" /> 
     </catel:StackGrid.RowDefinitions> 

     <Label Content="{Binding Title}" Foreground="White" Grid.Row="0" /> 
     <Label Content="Here goes your real content" Foreground="White" Grid.Row="1"/> 

     <ListBox Grid.Row="2" ItemsSource="{Binding PlayersCollection}" SelectedItem="{Binding SelectedPlayer}"> 
      <ListBox.ItemTemplate> 
       <DataTemplate> 
        <StackPanel> 
         <Label Content="{Binding ColumnValue}" /> 
        </StackPanel> 
       </DataTemplate> 
      </ListBox.ItemTemplate> 
     </ListBox> 


     <!--<views:PlayersView Grid.Column="1" DataContext="{Binding SelectedPlayer}" />--> 

    </catel:StackGrid> 
</catel:UserControl> 

    namespace FootballSim.Views 
{ 
    using Catel.Windows.Controls; 
    using FootballSim.ViewModels; 

    public partial class PlayersView : UserControl 
    { 
     public PlayersView() 
     { 
      InitializeComponent(); 
     } 
    } 
} 

    namespace FootballSim.ViewModels 
{ 
    using Catel.MVVM; 
    using FootballSim.Models; 
    using System.Collections.Generic; 

    /// <summary> 
    /// UserControl view model. 
    /// </summary> 
    public class PlayersViewModel : ViewModelBase, IPlayersViewModel 
    { 
     public List<Player> Players { get; protected set; } 

     public PlayersViewModel(List<Player> players) : base() 
     { 
      Players = players; 
     } 

     public override string Title { get { return "View model title"; } } 

     // TODO: Register models with the vmpropmodel codesnippet 
     // TODO: Register view model properties with the vmprop or vmpropviewmodeltomodel codesnippets 
     // TODO: Register commands with the vmcommand or vmcommandwithcanexecute codesnippets 

    } 
} 

답변

0

Catel에서 탐색의 방법은 여러 가지가 있습니다

  • IUIVisualizerService =>
  • 하기/etc

어쩌면 그것은

  • INavigationService => 페이지로 이동/닫기 응용 프로그램의 다른 대화 상자 표시 getting started guide of Catel을 읽는 것이 좋습니다.