亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在UserControl中綁定文本塊

在UserControl中綁定文本塊

C#
慕婉清6462132 2021-05-18 17:31:27
我正在學習WPF和c#,我試圖在usercontrol中進行文本塊綁定。我有課 Seller.cs  public class SellerInfo    {        public string Name { get; set; }        public string ID { get; set; }        public float workTime { get; set; }        public float loginTime { get; set; }        public int soldTickets { get; set; }        public int ticketReservation { get; set; }        public float totalAmountP { get; set; }    }我想通過以下方式從數據庫獲取數據 public void accountInfo()    {        con = new SqlConnection(@"Data Source=DESKTOP-8T7J7IH;Initial Catalog=Db1234;Integrated Security=True");        con.Open();        string s1 = @"SELECT Name +' ' + Surname FROM Seller WHERE LoginUser = '12345'";        cmd = new SqlCommand(s1, con);        SqlDataReader rd = cmd.ExecuteReader();        do        {            while (rd.Read())            {                {                    SellerInfo item = new SellerInfo();                    item.Name = rd.GetString(0);                };            }        }        while (rd.NextResult());        rd.Close();    }在上面只有名稱的示例中,現在我有一個問題,如何將我綁定到文本塊并將其顯示在usercontrol中?我創建了類似的東西:<TextBlock x:Name="sellerName" HorizontalAlignment="Left" Margin="112,20,0,0" TextWrapping="Wrap" Text="{Binding Name}" VerticalAlignment="Top" Width="166"/>并閱讀有關內容,在UserControl中我應DataContext="{Binding RelativeSource={RelativeSource Self}}"稍后使用,我嘗試進行設置,DataContext=this;但仍然沒有結果。我讀了很多關于它的文章,但是我不知道如何在這個例子中得到它。
查看完整描述

2 回答

?
慕桂英4014372

TA貢獻1871條經驗 獲得超13個贊

您是否實現了INotifyPropertyChanged接口?


查看完整回答
反對 回復 2021-05-29
  • 2 回答
  • 0 關注
  • 188 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號