0
我有一些XAML綁定到視圖模型中的屬性,但我不希望它們更新,直到用戶單擊保存按鈕。看過MSDN後,看起來我可以使用BindingGroup.UpdateSources()。但是我不知道如何獲取我的XAML的容器元素,以便我可以同時更新綁定的屬性。我的代碼背後需要什麼?按鈕單擊更新綁定
這是我的XAML:
<DockPanel VerticalAlignment="Stretch" Height="Auto">
<Border DockPanel.Dock="Top" BorderBrush="Black" BorderThickness="2">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.BindingGroup>
<BindingGroup Name="myBindingGroup1">
</BindingGroup>
</Grid.BindingGroup>
<TextBlock Grid.Column="0" Grid.Row="0" Text="Address:" />
<TextBox Grid.Column="1" Grid.Row="0" Text="{Binding myObject.Address, BindingGroupName=myBindingGroup1, UpdateSourceTrigger=Explicit}" />
<TextBlock Grid.Column="0" Grid.Row="1" Text="ID:" />
<TextBox Grid.Column="1" Grid.Row="1" Text="{Binding myObject.ID, BindingGroupName=myBindingGroup1, UpdateSourceTrigger=Explicit}" />
</Grid>
</Border>
<StackPanel Orientation="Horizontal" DockPanel.Dock="Bottom" Height="35" HorizontalAlignment="Center" VerticalAlignment="Bottom">
<Button Content="Save" Command="saveItem" />
</StackPanel>
</DockPanel>
你沒有找到我的答案有幫助嗎?你有嘗試過嗎? – 2014-12-24 10:00:49
是的,這是我最終做的,謝謝。我已經接受你的答案。 – yellavon 2014-12-24 16:03:53
很高興幫助你;) – 2014-12-24 16:04:48