Jim Hudson
10/31/2008 1:07:00 PM
Thanks for getting back to me, Zhi-Xin Ye.
The sequence of events, when my program runs, is this:
1) My UserControl is defined in the XAML, placed on a <Canvas>. Therefore,
it is constructed by the g.cs code for the <Page>. Its Visibility is
specified as "Collapsed" in the XAML code.
2) When the <Page> is displayed, the Load event for the UserControl is
fired. At that point, the DataContext for the UserControl is null, so the
binding for the TextBox does nothing. I ADDED THE CODE YOU SUGGESTED. IT
FIRED AT THIS POINT AND DID NOT FIX THE PROBLEM.
3) Later, as a result of the user operating another control on the <Page>,
the code-behind logic that I showed in my original message is fired: the
DataContext for the <UserControl> is set, the Visibility for the
<UserControl> is set to "Visible", and the UpdateSource() method is called
for the textbox's binding expression.
4) The FIRST time the <UserControl> is made visible, the adorners defined in
the error template are NOT displayed. However, the NEXT time (and all
subsequent times), the adorners ARE displayed.
5) At one point, I added an experimental TextBox to the UserControl, binding
the Text property of the experimental TextBox to the Validation.HasError
property of the other TextBox. Every time the UserControl was displayed,
that experimental TextBox contained "true" (the FIRST and all subsequent
times). So, I'm sure that the Validation is firing on that FIRST display,
and I'm sure that it's setting the property that triggers the error template.
Clearly, something happens after my code-behind logic executes and before
the UserControl is displayed for the first time. Whatever it is, that
"mystery event" has to occur before my error template adorners appear.
Perhaps some error template layer gets created? Whatever it is, I need to
force it to happen sooner in the processing. Do you have any idea what that
"mystery event" might be?
--
Jim Hudson