技术开发 频道

详细解析WPF中的应用程序模型

  (10)主窗口UI上另一个关键元素是状态栏。让我们在StatusBar元素里放置一个TextBlock:

<!-- Status Bar -->
<DockPanel
  
Name="DockPanel_Statusbar"
  Grid.Column
="0"
  Grid.ColumnSpan
="2"
  Grid.Row
="3">
  
<StatusBar
    
BorderBrush="Black"
    BorderThickness
="1">
    
<TextBlock Name="tb" Foreground="Black">
      Status bar
    
</TextBlock>
  
</StatusBar>
</DockPanel>

  (11)最后是右手边的窗口框。在左边ListItems显示之后,选择一条联系人,就会在右手边的这个Frame_RightPane里显示这个联系人的详细信息:

<!-- RightPanel -->
<Frame Name="Frame_RightPane"
  Grid.Column
="1"
  Grid.Row
="2"/>

 

  (12)到此为止,我们已经在XAML里完成了UI元素的添加,是时候看看后面的代码了。在MainWindow.xaml.cs文件里,为MainWindow这个类添加ExitApplication,NotImplementedMsg,WindowLoaded,ListItemSelected和LaunchNewContactWizard方法。您会注意到后三个方法的实现是空的。我们稍后再添加这部分逻辑。

//
        
// Triggered on Window load. Sets the ContactList collection
        
// as the Data Context.
        
//
        private void WindowLoaded(object sender, RoutedEventArgs e)
        {
        }
        
//
        
// Triggers application shutdown
        
//
        void ExitApplication(object sender, RoutedEventArgs e)
        {
            
this.Close();
        }
        
//
        
// Shows a message box informing user that a feature
        
// hasn't been implemented.
        
//
        void NotImplementedMsg(object sender, RoutedEventArgs e)
        {
            MessageBox.Show(
"This feature has not been implemented.",
                            
"Not Implemented");
        }
        
//
        
// Triggered when an item in the Contacts list is selected
        
//
        void ListItemSelected(object sender,
                                    SelectionChangedEventArgs args)
        {
        }
        
//
        
// Triggered when context menu or other toolbar option
        
// is clicked to launch
        
// 'Create a new contact' dialog
        
//
        private void LaunchNewContactWizard(object sender,
                                                   RoutedEventArgs e)
        {
        }

 

  (13)生成并运行您的应用程序。地址簿应用程序的基本框架已经搭好了。因为我们尚未初始化或使用联系人的信息,您在程序的左右面板上不会看到任何数据。在这一步,您的应用程序看上去是这样的:

1
相关文章