我该如何解决这个问题? [英] How do I fix this problem?

查看:63
本文介绍了我该如何解决这个问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!这一切都很新鲜。因为我的小宝贝,我没有那么多时间。感谢我能得到的任何帮助。

这是代码。

XAML:

 <   window     x:class   =  Aukcija1.MainWindow    xmlns:x   =  #unknown >  
xmlns =http://schemas.microsoft.com/winfx/2006/xaml/presentation
xmlns:x =http://schemas.microsoft.com/winfx/2006/xaml
Title =AuctionsHeight =350Width =525>
xmlns:wf =clr-namespace:System.Windows.Forms; assembly = System.Windows.Forms>

< grid > ;
DataContext ={Binding}>
< datagrid > AutoGeneratedColumns =FalseEnableRowVirtualization =TrueHeight =264Horizo​​ntalAlignment =LeftItemsSource ={Binding}Name =aukcija_bazeDataGridRowDetailsVisibilityMode =VisibleWhenSelectedVerticalAlignment =TopWidth =503SelectionChanged = aukcija_bazeDataGrid_SelectionChanged>
< datagrid.columns >
< datagridtextcolumn x:name = aukcijaIDColumn binding = {Binding Path = auction_ID} header = 拍卖ID width = SizeToHeader / >
< datagridtextcolumn x:name = < span class =code-keyword> artikalNameColumn binding = {Binding Path = item_name} 标题 = 项目名称 width = SizeToHeader / >
< datagridtextcolumn x:name = pocetnacijenaColumn binding = {Binding Path = start_price} header = 起始价格 width = SizeToHeader / >
< datagridtextcolumn x:name = trenutnacijenaColumn binding = {绑定路径= current_price} header = 当前价格 width < span class =code-keyword> = SizeToHeader / >
< / datagrid.columns >
< / datagrid >
< 按钮 内容 = 登录 高度 = 23 Horizo​​ntalAlignment = 保证金 = 331,276,0,0 名称 = button1 VerticalAlignment = Top Width = 75 点击 = button1_Click / >
< 按钮 内容 = 新拍卖 高度 = 23 Horizo​​ntalAlignment = 保证金 = 416,276,0,0 名称 = button3 VerticalAlignment = < span class =code-keyword> Top 宽度 = 75 点击 = button3_Click / >
< 按钮 内容 = 买入价 高度 = 23 Horizo​​ntalAlignment = 保证金 = 12,276,0,0, 名称 = button2 < span class =code-attribute> VerticalAlignment = 顶部 宽度 = 75 点击 < span class =code-keyword> = button2_Click / >
< / grid >

< / window >

C#



 使用系统; 
使用 System.Collections.Generic;
使用 System.Linq;
使用 System.Text;
使用 System.Windows;
使用 System.Windows.Controls;
使用 System.Windows.Data;
使用 System.Windows.Documents;
使用 System.Windows.Input;
使用 System.Windows.Media;
使用 System.Windows.Media.Imaging;
使用 System.Windows.Navigation;
使用 System.Windows.Shapes;
使用 System.Data.SqlClient;
使用 System.Data;
使用 System.Windows.Threading;
使用 System.Windows.Forms;
使用 System.Timers;



命名空间 Aukcija1
{
/// < 摘要 < span class =code-summarycomment>>
/// MainWindow.xaml的交互逻辑
/// < / summary >
public partial class MainWindow:Window
{
DispatcherTimer计时器;
int interval;
int 步骤;

public MainWindow()
{
interval = 1001 ;
step = 20 ;
timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromMilliseconds(interval);
timer.Start();
timer.Tick + = new EventHandler(timer_Tick);

DataTable AuctionsTable = new DataTable();
SqlConnection conn = new SqlConnection( @ datasource =(local); database = Aukcija; integrated security = true;);
SqlDataAdapter aukcDa = new SqlDataAdapter( select *来自拍卖,conn);

aukcDa.Fill(AuctionsTable);
aukcija_bazeDataGrid.DataContext = AuctionsTable;

}

private void InitializeComponent()
{
throw new NotImplementedException();
}

void timer_Tick( object sender,EventArgs e)
{
if (Canvas.GetLeft(button1)> 400
timer.Stop();
step =(步> 1 )? (step - = 1 ): 1 ;
Canvas.SetLeft(button1,Canvas.GetLeft(button1)+ step);
if (interval > 1
timer.Interval = TimeSpan.FromMilliseconds(interval - = 100 );
}

private void listBox1_SelectionChanged( object sender,SelectedCellsChangedEventArgs e)
{
using (SqlConnection conn = new SqlConnection())
{
conn.ConnectionString =( @ datasource =(local); database = Aukcija; integrated security = true;);
SqlCommand command = conn.CreateCommand();
command.CommandType = CommandType.StoredProcedure;
command.CommandText = uspPovecajCenuArtiklaZaJedan;
command.Parameters.AddWithValue( @ auction_ID,aukcija_bazeDataGrid.SelectedValue);
conn.Open();
command.ExecuteNonQuery();
}

}

private void button1_Click( object sender,RoutedEventArgs e)
{
Form1 popup = new Form1();
popup.ShowDialog();

popup.Dispose();
}

private void button3_Click( object sender,RoutedEventArgs e)
{
Form2 popup = new Form2();
popup.ShowDialog();

popup.Dispose();
}

private void button2_Click( object sender,RoutedEventArgs e)
{
using (SqlConnection conn = new SqlConnection())
{
conn.ConnectionString =( @ datasource =(local); database = Aukcija; integrated secutiry = true;);

SqlCommand command = conn.CreateCommand();
command.CommandType = CommandType.StoredProcedure;
command.CommandText = uspPovecajCenuArtiklaZaJedan;
command.Parameters.AddWithValue( @ auction_ID 1 );
conn.Open();
command.ExecuteNonQuery();
}
}

私有 void loadGrid( )
{
SqlConnection con = new SqlConnection( @ datasource =(local); database = Aukcija; integrated secutiry = true;);
SqlDataAdapter ad = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand();
con.Open();
string strQuery = 从拍卖中选择* ;
cmd.CommandText = strQuery;
ad.SelectCommand = cmd;
cmd.Connection = con;
DataSet ds = new DataSet();
ad.Fill(ds);
aukcija_bazeDataGrid.DataContext = ds.Tables [ 0 ]。DefaultView;
con.Close();
}

private void aukcija_bazeDataGrid_SelectionChanged( object sender,SelectedCellsChangedEventArgs e)
{

}

public UIElement button1 { get ; set ; }
}
}

SQL表格:



拍卖(auction_ID,item_name ,start_price,current_price)。









我收到这些错误:

当前上下文中不存在名称'aukcija_bazeDataGrid'

对象'Window'已经有一个子项,无法添加''。 '窗口'只能接受一个孩子。属性'Content'设置不止一次。

解决方案

嗯,是的。你需要将 Window.Content 设置为可以有多个子节点的东西,例如 System.Windows.Controls.DockPanel System.Windows.Controls.Grid System.Windows.Controls.Primitives.TabPanel 派生自System.Windows.Controls.Panel 等等。

请参阅: http://msdn.microsoft.com/en-us/library/system.windows.controls.panel.aspx#inheritanceContinued [ ^ 你需要了解的是WPF 内容模型http://msdn.microsoft.com/en-us/library/bb613548%28v=vs.110%29.aspx [ ^ ]。



-SA

Hi people! I am pretty new in all this. And I don't have so much time because of my little baby. I appreciate any help I can get.
Here is the code.
XAML:

<window x:class="Aukcija1.MainWindow" xmlns:x="#unknown">
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Auctions" Height="350" Width="525">
    xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"> 
    
    <grid>
DataContext="{Binding}">
        <datagrid> AutoGeneratedColumns="False" EnableRowVirtualization="True" Height="264" HorizontalAlignment="Left" ItemsSource="{Binding}" Name="aukcija_bazeDataGrid" RowDetailsVisibilityMode="VisibleWhenSelected" VerticalAlignment="Top" Width="503" SelectionChanged="aukcija_bazeDataGrid_SelectionChanged" >
            <datagrid.columns>
                <datagridtextcolumn x:name="aukcijaIDColumn" binding="{Binding Path=auction_ID}" header="Auction ID" width="SizeToHeader" />
                <datagridtextcolumn x:name="artikalNameColumn" binding="{Binding Path=item_name}" header="Item Name" width="SizeToHeader" />
                <datagridtextcolumn x:name="pocetnacijenaColumn" binding="{Binding Path=start_price}" header="Start Price" width="SizeToHeader" />
              <datagridtextcolumn x:name="trenutnacijenaColumn" binding="{Binding Path=current_price}" header="Current Price" width="SizeToHeader" />
            </datagrid.columns>
        </datagrid>
     <Button Content="Login" Height="23" HorizontalAlignment="Left" Margin="331,276,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
     <Button Content="New Auction" Height="23" HorizontalAlignment="Left" Margin="416,276,0,0" Name="button3" VerticalAlignment="Top" Width="75" Click="button3_Click" />
     <Button Content="Bid Price" Height="23" HorizontalAlignment="Left" Margin="12,276,0,0," Name="button2" VerticalAlignment="Top" Width="75" Click="button2_Click" />
    </grid>

</window>

C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data.SqlClient;
using System.Data;
using System.Windows.Threading;
using System.Windows.Forms;
using System.Timers;



namespace Aukcija1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        DispatcherTimer timer;
        int interval;
        int step;

        public MainWindow()
        {
            interval = 1001;
            step = 20;
            timer = new DispatcherTimer();
            timer.Interval = TimeSpan.FromMilliseconds(interval);
            timer.Start();
            timer.Tick += new EventHandler(timer_Tick);

            DataTable AuctionsTable = new DataTable();
            SqlConnection conn = new SqlConnection(@"datasource=(local);database=Aukcija;integrated security=true;");
            SqlDataAdapter aukcDa = new SqlDataAdapter("select * from auctions", conn);

            aukcDa.Fill(AuctionsTable);
            aukcija_bazeDataGrid.DataContext = AuctionsTable;

        }

        private void InitializeComponent()
        {
            throw new NotImplementedException();
        }

        void timer_Tick(object sender, EventArgs e)
        {
            if (Canvas.GetLeft(button1) > 400)
                timer.Stop();
            step = (step > 1) ? (step -= 1) : 1;
            Canvas.SetLeft(button1, Canvas.GetLeft(button1) + step);
            if (interval > 1)
                timer.Interval = TimeSpan.FromMilliseconds(interval -= 100);
        }

        private void listBox1_SelectionChanged(object sender, SelectedCellsChangedEventArgs e)
        {
            using (SqlConnection conn = new SqlConnection())
            {
                conn.ConnectionString = (@"datasource=(local);database=Aukcija;integrated security=true;");
                SqlCommand command = conn.CreateCommand();
                command.CommandType = CommandType.StoredProcedure;
                command.CommandText = "uspPovecajCenuArtiklaZaJedan";
                command.Parameters.AddWithValue("@auction_ID", aukcija_bazeDataGrid.SelectedValue);
                conn.Open();
                command.ExecuteNonQuery();
            }

        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            Form1 popup = new Form1();
            popup.ShowDialog();

            popup.Dispose();
        }

        private void button3_Click(object sender, RoutedEventArgs e)
        {
            Form2 popup = new Form2();
            popup.ShowDialog();

            popup.Dispose();
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            using (SqlConnection conn = new SqlConnection())
            {
                conn.ConnectionString = (@"datasource=(local);database=Aukcija;integrated secutiry=true;");

                SqlCommand command = conn.CreateCommand();
                command.CommandType = CommandType.StoredProcedure;
                command.CommandText = "uspPovecajCenuArtiklaZaJedan";
                command.Parameters.AddWithValue("@auction_ID", 1);
                conn.Open();
                command.ExecuteNonQuery();
            }
        }

        private void loadGrid()
        {
            SqlConnection con = new SqlConnection(@"datasource=(local);database=Aukcija;integrated secutiry=true;");
            SqlDataAdapter ad = new SqlDataAdapter();
            SqlCommand cmd = new SqlCommand();
            con.Open();
            string strQuery = "select * from Auctions";
            cmd.CommandText = strQuery;
            ad.SelectCommand = cmd;
            cmd.Connection = con;
            DataSet ds = new DataSet();
            ad.Fill(ds);
            aukcija_bazeDataGrid.DataContext = ds.Tables[0].DefaultView;
            con.Close();
        }

        private void aukcija_bazeDataGrid_SelectionChanged(object sender, SelectedCellsChangedEventArgs e)
        {

        }

        public UIElement button1 { get; set; }
    }
}

SQL table:

Auctions (auction_ID, item_name, start_price, current_price).





I got these errors:
The name 'aukcija_bazeDataGrid' does not exist in the current context
The object 'Window' already has a child and cannot add ''. 'Window' can accept only one child. The property 'Content' is set more than once.

解决方案

Well, yes. You need to set Window.Content to something which can have multiple children, such as System.Windows.Controls.DockPanel, System.Windows.Controls.Grid, System.Windows.Controls.Primitives.TabPanel, derived from System.Windows.Controls.Panel, and a lot more.
Please see: http://msdn.microsoft.com/en-us/library/system.windows.controls.panel.aspx#inheritanceContinued[^].

What you need to understand is the WPF content model: http://msdn.microsoft.com/en-us/library/bb613548%28v=vs.110%29.aspx[^].

—SA


这篇关于我该如何解决这个问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆