如何乘以一个绑定值 [英] How to multiply a bound value

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

问题描述

我想将两个文本框相乘,其中一个绑定到一个标签,另一个文本框中有一个值。



我试图将它们两者加在一起,但我不断得到'nameoftextbox'不存在,因为它与标签绑定。我如何得到它以便将两个文本框相乘?


所以低于它的说是UserProvided不存在,即使它确实存在。


请有人帮忙。


谢谢


 textboxDisplay1 =转换。 ToDouble(UserProvided.Text); 
textboxdisplay2 = Convert.ToDouble(Setnumber.Text);

解决方案

您好SnookerFan147,


根据您的描述,您有两个TextBox,一个是绑定标签的内容,另一个是有价值的,现在您想要获取两个文本框值。我尝试在我这边做一个简单的样本,但我没有这个问题,请看看:

< StackPanel> 
< Label Name =" label1"含量=" 12英寸;>< /标签>
< TextBox Name =" textbox1"宽度= QUOT; 200"高度= QUOT; 30英寸;余量= QUOT; 10" Text =" {Binding ElementName = label1,Path = Content}">< / TextBox>
< TextBox Name =" textbox2"宽度= QUOT; 200"高度= QUOT; 30英寸;余量= QUOT; 10"文本= QUOT; 10">< /文本框>
< / StackPanel>


 double v1; 
double v2;
double.TryParse(textbox1.Text,out v1);
double.TryParse(textbox2.Text,out v2);
Console.WriteLine("值1是{0},值2是{1}",v1,v2);

顺便说一下,我建议你可以使用Double.TryPrase方法将字符串转换为Double。


最好的问候,


Cherry



I am tring to multiply 2 textboxes together, one of them is bound to a label and the other textbox has a value within it.

I am trying to multiply both of them together, but I keep getting 'nameoftextbox' does not exist, presumerably because it is bound to the label. How to I get it so that it multiplies the two textboxes together?

So below it was say UserProvided does not exist, even though it does.

Please can somebody help.

Thank you

   textboxDisplay1 = Convert.ToDouble(UserProvided.Text);
            textboxdisplay2 = Convert.ToDouble(Setnumber.Text);

解决方案

Hi SnookerFan147,

According to your description, you have two TextBox, one is binding label's content, another is having value, now you want to get the two textbox value. I try to do one simple sample at my side, but I don't have this problem, please take a look:

 <StackPanel>
        <Label Name="label1" Content="12"></Label>
        <TextBox Name="textbox1" Width="200" Height="30" Margin="10" Text="{Binding ElementName=label1, Path=Content}"></TextBox>
        <TextBox Name="textbox2" Width="200" Height="30" Margin="10" Text="10"></TextBox>
    </StackPanel>

  double v1;
            double v2;
            double.TryParse(textbox1.Text,out v1);
           double.TryParse(textbox2.Text,out v2);
            Console.WriteLine("the value 1 is {0}, the value 2 is {1}",v1,v2);

By the way, I suggest you can use Double.TryPrase method to convert string to Double.

Best Regards,

Cherry


这篇关于如何乘以一个绑定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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