在Silverlight 4中,我有一个与
绑定的内容控件AddEditUser.DataContext=SomeUser;
问题是当我在字段中输入数据时,我检查了对象,但它不包含我在字段中输入的数据。
<ContentControl Name="AddEditUser">
<Grid Width="392" Height="183">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="77*" />
<ColumnDefinition Width="168" />
<ColumnDefinition Width="100" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Row="0" Grid.Column="0" Text="Add/Edit User"/>
<Button Grid.Row="0" Grid.Column="1" Width="50" Content="New" Click="Button_Click" />
<StackPanel Orientation="Horizontal" Grid.Row="0" Grid.Column="2" >
<Button Width="50" Content="Save" Click="Button_Click_1" />
<Button Width="50" Content="Delete" Click="Button_Click_2" />
</StackPanel>
<TextBlock Grid.Row="1" Grid.Column="0" Text="User name:"/>
<TextBox Grid.Row="1" Grid.Column="1" Text="{Binding Path=Username}" Name="UserName" Width="168"></TextBox>
<TextBlock Grid.Row="2" Grid.Column="0" Text="Password:"/>
<TextBox Grid.Row="2" Grid.Column="1" Text="{Binding Path=Password}" Width="168"></TextBox>
<TextBlock Grid.Row="3" Grid.Column="0" Text="First name:"/>
<TextBox Grid.Row="3" Grid.Column="1" Text="{Binding Path=FirstName}" Width="168"></TextBox>
<TextBlock Grid.Row="4" Grid.Column="0" Text="Last name:"/>
<TextBox Grid.Row="4" Grid.Column="1" Text="{Binding Path=LastName}" Width="168"></TextBox>
<TextBlock Grid.Row="5" Grid.Column="0" Text="Admin:"/>
<CheckBox Grid.Row="5" Grid.Column="1" Name="AdminCheckbox" Content="{Binding Path=Admin}" Width="168"/>
<TextBlock Grid.Row="6" Grid.Column="0" Text="Title:"/>
<TextBox Grid.Row="6" Grid.Column="1" Text="{Binding Path=Title}" Width="168"></TextBox>
<TextBlock Grid.Row="7" Grid.Column="0" Text="Email:"/>
<TextBox Grid.Row="7" Grid.Column="1" Text="{Binding Path=Email}" Width="168"></TextBox>
</Grid>
</ContentControl>
答案 0 :(得分:1)
在文本框中使用TwoWay
绑定,以便在对象的字段中输入数据。默认绑定模式是单向的。