1

How do I achieve following XAML Code in Ammy.

<Label>First Name:</Label>
<TextBox x:Name="txtFirstName" Width="100" MaxLength="10" Text="{Binding FirstName}" />
<Label >Last Name:</Label>
<TextBox Width="100">
  <TextBox.Style>
    <Style TargetType="TextBox">
      <Setter Property="Text" Value="{Binding LastName}" />
        <Style.Triggers>
          <DataTrigger Binding="{Binding ElementName=chk, Path=IsChecked, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Value="True">
             <Setter Property="Text" Value="{Binding ElementName=txtFirstName, Path=Text, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
          </DataTrigger>
         </Style.Triggers>
     </Style>
 </TextBox.Style>
</TextBox>
<CheckBox x:Name="chk" Content="CopyFirstNameToLast" />

Help would be appreciated.

4

1 回答 1

1

It should look something like this:

Label { "First Name:" }
TextBox "txtFirstName" {
  Width: 100
  MaxLength: 10
  Text: bind FirstName
}

Label { "Last Name:" }
TextBox {
  Width: 90
  Style: Style {
    TargetType: TextBox
    #Setter("Text", bind LastName)

    Triggers: DataTrigger {
      Binding: bind IsChecked from "chk" set [ Mode: TwoWay, UpdateSourceTrigger: PropertyChanged]
      Value: "True"
      Setter {
        Property: "Text" 
        Value: bind Text from "txtFirstName" set [ Mode: TwoWay, UpdateSourceTrigger: PropertyChanged ]
      }
    }
  }
}
CheckBox "chk" { "CopyFirstNameToLast" }

EDIT: By the way. If you don't want to convert existing binding to Ammy, you can use XAML syntax i.e. Binding: "{Binding ElementName=chk, Path=IsChecked, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"

于 2017-01-27T12:22:30.677 回答