使用用户输入绘制矩形 [英] Drawing a Rectangle Using User Input

查看:80
本文介绍了使用用户输入绘制矩形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是WPF的新手,正在开发我的第一个测试应用程序.我有2个输入供用户填写:

  • 宽度(以毫米为单位).
  • 高度(以毫米为单位).
  • I''m new to WPF and developing my first test application. I have 2 inputs that the user can fill in:

    • Width (in millimeters).
    • Height (in millimeters).
    •            Width: 2000 mm
            _______________________
           |                       |
      H    |                       |
      E    |                       |
      I    |                       |
      G    |                       |
      H    |                       |
      T    |                       |
      :    |                       |
      3    |                       |
      0    |                       |
      0    |                       |
      0    |                       |
      mm   |_______________________|



      有人可以帮我提供代码示例或一些提示吗?



      Can somebody help me with a code example or some tips?

      推荐答案

      尝试一下:
      Give this a try:
      <Grid>
          <Grid.RowDefinitions>
              <RowDefinition Height="Auto" />
              <RowDefinition Height="Auto" />
              <RowDefinition />
          </Grid.RowDefinitions>
          <TextBox Name="w" Grid.Row="0" Text="200" />
          <TextBox Name="h" Grid.Row="1" Text="120" />
          <!-- This can be a Rectangle if you want. -->
          <Label Grid.Row="2" Content="Hello" Background="Red"
      
              Width="{Binding ElementName=w, Path=Text}"
      
              Height="{Binding ElementName=h, Path=Text}" />
      </Grid>


      如果要将值乘以某个常数,请使用以乘法因子为参数的IValueConverter(Google会告诉您所有您需要了解的信息).


      If you want to multiply the values by some constant, use an IValueConverter (Google will tell you all you need to know about those) that takes the multiply factor as a parameter.


      这篇关于使用用户输入绘制矩形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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