欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

c#數(shù)據(jù)綁定之數(shù)據(jù)轉(zhuǎn)化為信息的示例

 更新時間:2014年04月10日 14:29:12   作者:  
這篇文章主要介紹了c#數(shù)據(jù)綁定中的數(shù)據(jù)轉(zhuǎn)化為信息的示例,需要的朋友可以參考下

目標界面:

XAML代碼:

復制代碼 代碼如下:

<Grid Margin="2">
            <Grid.RowDefinitions>
                <RowDefinition  Height="Auto"/>
                <RowDefinition  Height="Auto"/>
                <RowDefinition  Height="Auto"/>
                <RowDefinition />
            </Grid.RowDefinitions>
            <GroupBox Header="Customer" Grid.Row="0" Padding="5">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition />
                        <RowDefinition />
                        <RowDefinition/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <TextBlock Grid.Row="0" Grid.Column="0" Text="CustomerID" Margin="2" HorizontalAlignment="Right" VerticalAlignment="Center"/>
                    <TextBox Grid.Row="0" Grid.Column="1" Margin="2" Name="tbxCustomerID" Text="{Binding Path=CID}"/>
                    <TextBlock Grid.Row="1" Grid.Column="0" Text="CustomerName" Margin="2" HorizontalAlignment="Right" VerticalAlignment="Center"/>
                    <TextBox Grid.Row="1" Grid.Column="1" Margin="2" Name="tbxCustomerName" Text="{Binding Path=Name}"/>
                    <Button Grid.Row="2" Grid.Column="1" Content="Add New Customer" Margin="2" Name="btnAddCustomer" Padding="2" Click="btnAddCustomer_Click" />
                </Grid>
            </GroupBox>
            <GroupBox Header="Order" Grid.Row="1" Padding="5">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition />
                        <RowDefinition />
                        <RowDefinition />
                        <RowDefinition />
                        <RowDefinition />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition/>
                    </Grid.ColumnDefinitions>
                    <TextBlock Grid.Row="0" Grid.Column="0" Text="OrderID" Margin="2" HorizontalAlignment="Right" VerticalAlignment="Center"/>
                    <TextBox Grid.Row="0" Grid.Column="1" Margin="2" Name="tbxOrderID" Text="{Binding Path=OID}"/>
                    <TextBlock Grid.Row="1" Grid.Column="0" Text="OrderName" Margin="2" HorizontalAlignment="Right" VerticalAlignment="Center"/>
                    <TextBox Grid.Row="1" Grid.Column="1" Margin="2" Name="tbxOrderName" Text="{Binding Path=Customer}"/>
                    <TextBlock Grid.Row="2" Grid.Column="0" Text="Subtotal" Margin="2" HorizontalAlignment="Right" VerticalAlignment="Center"/>
                    <TextBox Grid.Row="2" Grid.Column="1" Margin="2" Name="tbxSubtotal" Text="{Binding Path=Subtotal}"/>
                    <TextBlock Grid.Row="3" Grid.Column="0" Text="TaxRate" Margin="2" HorizontalAlignment="Right" VerticalAlignment="Center"/>
                    <TextBox Grid.Row="3" Grid.Column="1" Margin="2" Name="tbxTaxRate" Text="{Binding Path=TaxRate}"/>
                    <Button Grid.Row="4" Grid.Column="1" Content="Add New Order" Margin="2" Name="btnAddOrder" Padding="2" Click="btnAddOrder_Click" />
                </Grid>
            </GroupBox>
            <ListView Name="lstDisplayCustomer" ItemsSource="{Binding}" Grid.Row="2"  Margin="2" MinHeight="150">
                <ListView.View>
                    <GridView>
                        <GridView.Columns>
                            <GridViewColumn  Header="CustomerID" DisplayMemberBinding="{Binding CID}"/>
                            <GridViewColumn Header="CustomerName" DisplayMemberBinding="{Binding Name}"/>
                            <GridViewColumn Header="Total" DisplayMemberBinding="{Binding OrderTotals}" />
                        </GridView.Columns>
                    </GridView>
                </ListView.View>
            </ListView>
            <ListView Name="lstDisplayOrder" ItemsSource="{Binding}" Grid.Row="3"  Margin="2" MinHeight="150">
                <ListView.View>
                    <GridView>
                        <GridView.Columns>
                            <GridViewColumn  Header="OrderID" DisplayMemberBinding="{Binding OID}"/>
                            <GridViewColumn Header="Customer" DisplayMemberBinding="{Binding Customer}"/>
                            <GridViewColumn Header="Subtotal" DisplayMemberBinding="{Binding Subtotal}"/>
                            <GridViewColumn Header="TaxRate"  DisplayMemberBinding="{Binding TaxRate}" />
                            <GridViewColumn Header="Total"    DisplayMemberBinding="{Binding Total}"/>
                        </GridView.Columns>
                    </GridView>
                </ListView.View>
            </ListView>
        </Grid>

C# 代碼:

復制代碼 代碼如下:

DataSet business = NewData();

        public MainWindow()
        {
            InitializeComponent();

        }

        private static DataSet NewData()
        {
            //-----build the parent table and add some data
            DataTable customer = new DataTable("Customer");
            customer.Columns.Add("CID", typeof(Int32));
            customer.Columns.Add("Name", typeof(string));
            //-------build the child table and add some data.
            DataTable orders = new DataTable("Order");
            orders.Columns.Add("OID", typeof(int));
            orders.Columns.Add("Customer", typeof(Int32));
            orders.Columns.Add("Subtotal", typeof(decimal));
            orders.Columns.Add("TaxRate", typeof(decimal));
            orders.Columns.Add("Total",typeof(decimal),"Subtotal*(1+TaxRate)");

            //-----Link the table within a Dataset.
            DataSet business = new DataSet();
            business.Tables.Add(customer);
            business.Tables.Add(orders);
            business.Relations.Add(customer.Columns["CID"],orders.Columns["Customer"]);
            customer.Columns.Add("OrderTotals" ,typeof(decimal),"Sum(Child.Total)");
            return business;
        }

        private void btnAddCustomer_Click(object sender, RoutedEventArgs e)
        {
           //Vist datatable customer.
            DataTable customer=business.Tables["Customer"];
            NewMember(customer);
            lstDisplayCustomer.DataContext = customer;
        }

        private DataTable NewMember(DataTable table)
        {
            DataRow newRow = table.NewRow();
            newRow["CID"] = tbxCustomerID.Text;
            newRow["Name"] = tbxCustomerName.Text;
            table.Rows.Add(newRow);
            return table;
        }

        private DataTable NewMemberOrder(DataTable table)
        {
            DataRow newRow = table.NewRow();
            newRow["OID"] = tbxOrderID.Text;
            newRow["Customer"] = tbxOrderName.Text;
            newRow["Subtotal"] = tbxSubtotal.Text;
            newRow["TaxRate"] = tbxTaxRate.Text;
            table.Rows.Add(newRow);
            return table;
        }

        private void btnAddOrder_Click(object sender, RoutedEventArgs e)
        {
            //Vist datatable order.
            DataTable order = business.Tables["Order"];
            NewMemberOrder(order);
            lstDisplayOrder.DataContext = order;
        }

相關(guān)文章

  • C#操作ini文件的幫助類

    C#操作ini文件的幫助類

    這篇文章介紹了C#操作ini文件的幫助類,文中通過示例代碼介紹的非常詳細。對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-04-04
  • C#中靜態(tài)方法和實例化方法的區(qū)別、使用

    C#中靜態(tài)方法和實例化方法的區(qū)別、使用

    這篇文章主要介紹了C#中靜態(tài)方法和實例化方法的區(qū)別、使用,文中講解的非常細致,對大家的學習有所幫助,感興趣的朋友可以了解下
    2020-06-06
  • c# this關(guān)鍵字用法代碼詳解

    c# this關(guān)鍵字用法代碼詳解

    在本篇文章里小編給大家整理的是關(guān)于c# this關(guān)鍵字用法以及相關(guān)實例代碼,有興趣的朋友們可以學習下。
    2020-02-02
  • c#獲取windows桌面背景代碼示例

    c#獲取windows桌面背景代碼示例

    這篇文章主要介紹了c#獲取windows桌面背景的方法,大家參考使用吧
    2013-12-12
  • C#生成code128條形碼的方法

    C#生成code128條形碼的方法

    這篇文章主要介紹了C#生成code128條形碼的方法,是C#程序設(shè)計中一個很實用的技巧,需要的朋友可以參考下
    2014-08-08
  • C#給PDF文件添加水印

    C#給PDF文件添加水印

    這篇文章主要為大家詳細介紹了C#給PDF文件添加水印的相關(guān)代碼,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-03-03
  • 解決在Unity中使用FairyGUI遇到的坑

    解決在Unity中使用FairyGUI遇到的坑

    這篇文章主要介紹了解決在Unity中使用FairyGUI遇到的坑,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2021-04-04
  • C#實現(xiàn)隨機數(shù)產(chǎn)生類實例

    C#實現(xiàn)隨機數(shù)產(chǎn)生類實例

    這篇文章主要介紹了C#實現(xiàn)隨機數(shù)產(chǎn)生類,實例分析了C#隨機數(shù)的實現(xiàn)技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    2015-03-03
  • c#版json數(shù)據(jù)解析示例分享

    c#版json數(shù)據(jù)解析示例分享

    JSON(全稱為JavaScript Object Notation) 是一種輕量級的數(shù)據(jù)交換格式。它是基于JavaScript語法標準的一個子集。 JSON采用完全獨立于語言的文本格式,可以很容易在各種網(wǎng)絡(luò)、平臺和程序之間傳輸。JSON的語法很簡單,易于人閱讀和編寫,同時也易于機器解析和生成
    2014-03-03
  • 深入理解C#的數(shù)組

    深入理解C#的數(shù)組

    本篇文章主要介紹了C#的數(shù)組,數(shù)組是一種數(shù)據(jù)結(jié)構(gòu),詳細的介紹了數(shù)組的聲明和訪問等,有興趣的可以了解一下。
    2016-11-11

最新評論