none
在WPF里如何实现像word2007“最近使用的文档”功能? RRS feed

  • 问题

  • 在Vs。net2010的wpf里如何实现像word2007“最近使用的文档”功能?部分源代码如下所示,请哪位高手帮忙指点,不甚感谢!

    <ribbon:RibbonApplicationMenu.AuxiliaryPaneContent>
    <ribbon:RibbonGallery   MaxColumnCount="1"  ScrollViewer.VerticalScrollBarVisibility="Auto">
          <TextBlock>最近使用的文档</TextBlock>
          <ribbon:RibbonSeparator/>
    <ribbon:RibbonGalleryCategory Name="RG"  PreviewMouseLeftButtonDown="RG_PreviewMouseLeftButtonDown" />
    </ribbon:RibbonGallery>                 
    </ribbon:RibbonApplicationMenu.AuxiliaryPaneContent>
    private void RibbonWindow_Activated(object sender, EventArgs e)
            {
                //打开Access 2010数据库文件
                string strConnection = "Provider = Microsoft.ACE.OLEDB.12.0;";                              //C#读取Access库的连接字符串  
                strConnection += @"Data Source = ";
                strConnection += System.IO.Directory.GetCurrentDirectory();
                strConnection += @"\BID.accdb";                                                             //指定数据库在硬盘的物理位置  
                {
                    objConnection.Open();                                                                   //打开连接                   
                    string cmdstr = "SELECT * FROM 工程项目名称表";                                         //判断表【桥位布孔】中是否有记录
                    OleDbCommand cmd = new OleDbCommand(cmdstr, objConnection);
                    OleDbDataReader dr = cmd.ExecuteReader();
                    if (dr.HasRows == false)
                    {
                        objConnection.Close();
                        return;
                    }
                    OleDbCommand sqlcmd = new OleDbCommand(@"select * from 工程项目名称表", objConnection); //sql语句
                    Microsoft.Windows.Controls.Ribbon.RibbonGalleryItem 最近打开工程项目名称子项 = new Microsoft.Windows.Controls.Ribbon.RibbonGalleryItem();
                    Microsoft.Windows.Controls.Ribbon.RibbonGallery rg1 = new Microsoft.Windows.Controls.Ribbon.RibbonGallery();
                    using (OleDbDataReader reader = sqlcmd.ExecuteReader())                                 //执行查询,用using替代reader.Close()  
                    {                                                                                       //表【桥位布孔】中有记录时,将其清空。                                                                 
                        while (reader.Read())                                                               //这个read调用很重要!不写的话运行时将提示找不到数据  
                        {
                            RG.Items.Add(reader["工程项目名称"].ToString());                                  //取得字段的值                        
                        }                   
                    }
                }
            }
    private void RG_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
        //这里取不到选中的“最近使用的文档”,即sender中传递的所选文件名。
    }

    2011年7月19日 14:18

答案

全部回复