【问题标题】:Placing wpf window in a folder将wpf窗口放在文件夹中
【发布时间】:2013-08-01 03:17:16
【问题描述】:

我有一个名为 SoftwareRosterForm 的表单:

namespace WpfsoftwareMonitoring.views
{

    public partial class SoftwareRosterForm : Window
    {
        public SoftwareRosterForm()
        {
            InitializeComponent();
        }
    }
}

还有一个 SoftwareRosterClass:

namespace WpfsoftwareMonitoring
{
    class SoftwareRosterClass
    {
        ConnectionManager DatabaseConnect = new ConnectionManager();
        DataSet SoftwareData = new DataSet();

        public void AddSoftwareFunction(SoftwareRosterForm SoftwareRosterPage)
        {
            if (SoftwareRosterPage.SoftName_txtbox.Text == "" || SoftwareRosterPage.SoftType_cmbbox.Text == "")
            {
                MessageBox.Show("Complete all the fields.");
            }
            else
            {
                DatabaseConnect.StringQuery = "SELECT * FROM SoftwareList_tbl WHERE Software_name = '" + SoftwareRosterPage.SoftName_txtbox.Text + "'";
                DatabaseConnect.GetData();
                if (DatabaseConnect.SQLDR.HasRows == true)
                {
                    DatabaseConnect.SQLDR.Close();
                    SoftwareRosterPage.SoftName_txtbox.SelectAll();
                    MessageBox.Show("Software already exist.");
                }

                else
                {
                    DatabaseConnect.SQLDR.Close();
                    DatabaseConnect.StringQuery = "INSERT INTO SoftwareList_tbl (Software_name, Software_type) VALUES ('" + SoftwareRosterPage.SoftName_txtbox.Text + "', '" + SoftwareRosterPage.SoftType_cmbbox.Text + "')";
                    DatabaseConnect.InsertData();
                    MessageBox.Show("Software added.");
                    DatabaseConnect.SQLDR.Close();
                    ClearFormFields(SoftwareRosterPage);
                    FilterSoftwareList(SoftwareRosterPage);
                    SoftwareRosterPage.SoftName_txtbox.Focus();
                }
            }
        }
        public void FilterSoftwareList(SoftwareRosterForm SoftwareRosterPage)
        {
            //SoftList_lstview.Items.Clear();
            DatabaseConnect.StringQuery = "SELECT Software_name, Software_type FROM SoftwareList_tbl";
            DatabaseConnect.GetData();
            DatabaseConnect.SQLDR.Close();

            //Fills the temporary table with the selected data and fills the list view
            DatabaseConnect.SQLDA.Fill(SoftwareData);
            SoftwareRosterPage.SoftList_lstview.DataContext = SoftwareData.Tables[0].DefaultView;

            DatabaseConnect.SQLDR.Close();
        }

        public void ClearFormFields(SoftwareRosterForm SoftwareRosterPage)
        {
            SoftwareRosterPage.SoftName_txtbox.Clear();
            SoftwareRosterPage.SoftType_cmbbox.SelectedIndex = -1;
        }
    }
}

我尝试在 public void AddSoftwareFunction(SoftwareRosterForm SoftwareRosterPage) 方法中传递 SoftwareRosterForm 但出现错误:

找不到类型或命名空间名称“SoftwareRosterForm”(您是否缺少 using 指令或程序集引用?)

但是当我删除命名空间WpfsoftwareMonitoring.Views 中的“视图”时,错误并没有发生,而是出现了另一个错误:

当前上下文中不存在名称“InitializeComponent”

有什么想法吗? 我将表单放在 Views 文件夹中,我尝试删除文件夹中的表单,效果很好,但我需要将表单放在文件夹中以保持整洁

我只是一名大学生,刚接触 c# 和 wpf

【问题讨论】:

    标签: c# wpf window directory


    【解决方案1】:

    您需要将WpfsoftwareMonitoring.views 命名空间添加到您的类文件中

    例子:

    using WpfsoftwareMonitoring.views
    
    namespace WpfsoftwareMonitoring
    {
        class SoftwareRosterClass
        {
          ..............
    

    【讨论】:

    • @sa_ddams213 谢谢老兄!这行得通!我正在迁移到 c#,我从来没有想过这会这么简单
    • 您应该安装 ReSharper。这是任何在 Visual Studio 中编写代码的人都应该使用的有价值的工具。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多