0

I'm trying to apply the trigger as follows:

using SmartRoutePlanner.Models;
...
Map locationMap = new Map();

locationTextBox.DataContext = locationMap;

Binding locationBinding = new Binding("Location");
locationTextBox.SetBinding(TextBox.TextProperty, locationBinding);
locationBinding.UpdateSourceTrigger = UpdateSourceTrigger.Explicit;

And my XAML code is this:

...
xmlns:models="clr-namespace:SmartRoutePlanner.Models"
...
<Grid.Resources>
    <models:Map x:Key="mapDataSource"/>
</Grid.Resources>
<Grid.DataContext>
    <Binding Source="{StaticResource mapDataSource}" />
</Grid.DataContext>
<TextBox x:Name="locationTextBox" />

What is causing the exceptions?

Kensing
  • 97
  • 1
  • 10
  • Try using XAML instead of Cod Behind to see if the error still persists. – trinaldi Oct 06 '13 at 19:21
  • Good idea. Your comment led me to this, which describes the problem in greater detail: http://stackoverflow.com/questions/12692885/updatesourcetrigger-propertychanged-equivalent-for-a-textbox-in-winrt-xaml – Kensing Oct 06 '13 at 19:28

1 Answers1

0

In XAML it should look like this:

<Window x:Class="Teste.Window1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Window1" Height="300" Width="300">
    <Grid>
        <TextBox Text="{Binding PropertyFromDataContext, UpdateSourceTrigger=Explicit}" />
    </Grid>
</Window>

Remember that you bind a property from your DataContext!

trinaldi
  • 2,872
  • 2
  • 32
  • 37