C# 在WPF C中按下按钮时自动更新label.content#

C# 在WPF C中按下按钮时自动更新label.content#,c#,wpf,C#,Wpf,我已经创建了一个有标签的应用程序。单击按钮时,我需要更新label.content XAML 部分值是从数据库中提取的。将labels width属性更改为auto。只需删除标签的宽度即可。它应该可以工作 <Label x:Name="lblTaxExcise" Content="Excise" HorizontalAlignment="Left" Margin="10,0,0,112" Grid.Row="2" Height="29" VerticalAlignment="Bott

我已经创建了一个有标签的应用程序。单击按钮时,我需要更新label.content

XAML


部分值是从数据库中提取的。

将labels width属性更改为auto。

只需删除标签的宽度即可。它应该可以工作

   <Label x:Name="lblTaxExcise" Content="Excise" HorizontalAlignment="Left" Margin="10,0,0,112" Grid.Row="2" Height="29" VerticalAlignment="Bottom"/>
   <Label x:Name="lblTaxEdu" Content="Edu. Cess" HorizontalAlignment="Left" Margin="10,0,0,78" Grid.Row="2" Height="29" VerticalAlignment="Bottom"/>
   <Label x:Name="lblTaxVat" Content="VAT" HorizontalAlignment="Left" Margin="10,0,0,44" Grid.Row="2" Height="29" VerticalAlignment="Bottom"/>


您遇到的问题或错误是……。?您遇到了什么错误?没有错误。它没有更新。如果在
语句中设置断点,而
语句中是否有
消费税
educcess
增值税
变量中的数据?我能看到的另一件事是,您已将标签设置为固定宽度,并且您的数据将超过该宽度,您可以删除宽度,或者将其设置为Autoyes@MarkHall。它们有默认文本。当我按下“添加产品”按钮时,我需要更新他们的文本。事实上,我认为我的代码是好的。我听说过背景工作者之类的事。我不知道到底该如何实现。
        SqlCeCommand com1 = new SqlCeCommand("SELECT ExciseTax, EduCessTax, VatTax FROM Tax_Master", con);
        SqlCeDataReader dr1 = com1.ExecuteReader();
        while (dr1.Read())
        {
            Excise = Convert.ToInt32(dr1[0]);
            EduCess = Convert.ToInt32(dr1[1]);
            Vat = Convert.ToInt32(dr1[2]);
        }
        lblTaxExcise.Content = "Excise @ " + Excise;
        lblTaxEdu.Content = "Edu. Cess @ " + EduCess;
        lblTaxVat.Content = "VAT @ " + Vat;
   <Label x:Name="lblTaxExcise" Content="Excise" HorizontalAlignment="Left" Margin="10,0,0,112" Grid.Row="2" Height="29" VerticalAlignment="Bottom"/>
   <Label x:Name="lblTaxEdu" Content="Edu. Cess" HorizontalAlignment="Left" Margin="10,0,0,78" Grid.Row="2" Height="29" VerticalAlignment="Bottom"/>
   <Label x:Name="lblTaxVat" Content="VAT" HorizontalAlignment="Left" Margin="10,0,0,44" Grid.Row="2" Height="29" VerticalAlignment="Bottom"/>