Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/257.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在文本块(UWP)上键入按钮内容_C#_Uwp - Fatal编程技术网

C# 在文本块(UWP)上键入按钮内容

C# 在文本块(UWP)上键入按钮内容,c#,uwp,C#,Uwp,在我的项目中,我有一个文本块 <TextBlock Name="MyDisplay" TextAlignment="Center" Style="{StaticResource HeaderTextBlockStyle}"/> 但此代码不起作用,它不是TextBlock中的更新编号 但在WindowsPhone8中也使用了同样的东西,虽然工作正常,但代码上的唯一区别是WindowsPhone8代码 public DisplayPad() { this.

在我的项目中,我有一个文本块

<TextBlock Name="MyDisplay" TextAlignment="Center"
           Style="{StaticResource HeaderTextBlockStyle}"/>
但此代码不起作用,它不是TextBlock中的更新编号

但在WindowsPhone8中也使用了同样的东西,虽然工作正常,但代码上的唯一区别是WindowsPhone8代码

public DisplayPad()
{
    this.InitializeComponent();
    ButtonPanel.AddHandler(Button.MouseLeftButtonUpEvent, new MouseButtonEventHandler(ScreenMarkupButton_MouseLeftButtonUp), true);

    UpdateDisplay();
}

    public void ScreenMarkupButton_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
    {
       Button button = e.OriginalSource as Button;
       if (button == null)
       return;
       string content = button.Content.ToString();            
       double digit;
       if (double.TryParse(content, out digit))            
       {
          //My Codes
       }
       UpdateDisplay();
    }
OriginalSource对象不是按钮,而是按钮内的内部文本块,因此需要将代码更改为

var textBlock = e.OriginalSource as TextBlock;
if (textBlock == null)
    return;
string content = textBlock.Text;

MyDisplay.Text=String.Format{0:.};错误是什么?在此代码中,您要打印什么?在windows 8 phone中,按钮的内容以文本块形式写入。格式,但在windows 10中,uwp同样不起作用。文本块上没有写入按钮的内容,因为mouseLeftButtonUpEvent在uwp中不可用。我想他可以使用Buttonsender并获得它。@lindexi,不是真的。这里的发送者是画布。但它是按钮内容而不是文本块,因为在uwp中没有EmouseLeftButtonUpEvent,所以这不起作用,当我按任意位时,什么都没有发生也建议我将按钮内容写入文本块的另一种方法,我将尝试您的代码,然后再次回复,您甚至可以尝试我的代码,并在string content=textBlock.Text行设置断点;还有测试?它起作用了。在我的回答中,我已经向你解释过,按钮中有一个内部文本块,它将提供你在按钮中定义的任何内容。
public DisplayPad()
{
    this.InitializeComponent();
    ButtonPanel.AddHandler(Button.MouseLeftButtonUpEvent, new MouseButtonEventHandler(ScreenMarkupButton_MouseLeftButtonUp), true);

    UpdateDisplay();
}

    public void ScreenMarkupButton_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
    {
       Button button = e.OriginalSource as Button;
       if (button == null)
       return;
       string content = button.Content.ToString();            
       double digit;
       if (double.TryParse(content, out digit))            
       {
          //My Codes
       }
       UpdateDisplay();
    }
var textBlock = e.OriginalSource as TextBlock;
if (textBlock == null)
    return;
string content = textBlock.Text;