2009-08-23 11 views
1

ListBoxの各項目にボタンがあるので、Binding.UpdateSourceTriggerがExplicitであるデータ項目のすべてのテキストボックスを設定しました。UpdateSourceTrigger = ListBoxなどのItemsコントロールに明示的に使用

ボタンのクリックにハンドラを追加しましたが、今は何ですか?

コントロールから情報を収集するにはどうすればよいですか?彼らは動的なキーを持っていない、どのようにBindingExpressionsを取得するのですか?

<ListBox ItemsSource="{Binding Path=Phones}"> 
    <ListBox.ItemTemplate> 
     <DataTemplate DataType="{x:Type data:Phone}"> 
      <StackPanel Style="{StaticResource StackPanelStyle}">     
       <TextBox Margin="5" VerticalAlignment="Center" Name="tbNumber" 
Text="{Binding Number, ValidatesOnExceptions=True, UpdateSourceTrigger=Explicit}" 
/> 
       <Button Click="btnSavePhone_Click" Margin="5" 
Content="_Update" IsEnabled="{Binding IsValid}" />     
      </StackPanel> 
     </DataTemplate> 
    </ListBox.ItemTemplate> 
</ListBox> 
+0

設定方法のサンプルコードを追加できますか? –

答えて

1
Private Sub btnSavePhone_Click(sender As Button, e As RoutedEventArgs) 
    'As I only have one TextBox I can use the following filter, 
    'you can of corse change it to Where c.Name = "tbNumber" 
    Dim tbNumber = From c As FrameworkElement In _ 
     DirectCast(sender.Parent, StackPanel).Children Where TypeOf c Is TextBox 
    Dim x = tbNumber.ToList 
    Dim be = tbNumber.Cast(Of TextBox).First _ 
       .GetBindingExpression(TextBox.TextProperty) 

    If Not be.HasError Then be.UpdateSource() 
End Sub 

更新
いくつかのシナリオでは、BindingGroupは、UがBindingGroup.UpdateSourcesを呼び出して、最善の解決策になります。

+0

BindingGroupの更新をありがとう。多くの助けになります! – Scott

関連する問題