使用用户输入绘制矩形

问题描述:

我是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.