views:

43

answers:

1

I've been tring to get this example to work, but there seems to be a bug in the code Label Target code, in that when you click on the second label the focus is set to the DatePicker rather than the TextBox, regardless which label you click first, also when you have entered the date the second label still sets it focus to DatePicker.

<!-- Unbound Date of Birth field -->
<sdk:Label Content="Date of Birth" IsRequired="True" Margin="5" />
<StackPanel Orientation="Horizontal" Grid.Column="1">
    <sdk:DatePicker Height="23" />
    <sdk:DescriptionViewer Description="Please enter your date of birth."/>
</StackPanel>

<!-- ID Number field -->
<sdk:Label Grid.Row="1" Margin="5" Target="{Binding ElementName=tbIdNumber}" />
<StackPanel Orientation="Horizontal" Grid.Column="1" Grid.Row="1">
    <TextBox x:Name="tbIdNumber" Height="23" Width="100"
             Text="{Binding IdNumber, Mode=TwoWay, 
                    ValidatesOnExceptions=True, NotifyOnValidationError=True}" />
    <sdk:DescriptionViewer Target="{Binding ElementName=tbIdNumber}"/>
</StackPanel>

I found this example here on the MSDN link text. To me this seems to be a bug, or am I just losing it?

Apologies if this is a duplicate question... I have googled this and all the examples seem to be the same, in that the target element is not being focused to.

A: 

It seems a reasonable assumption that clicking the label ought to move the focus to the associated control. However the Label does not actually provide that function.

AnthonyWJones
Another question if I may, why would you want to bind the Label in the manner they have? It doesn't seem to serve a useful purpose.I was looking at it like the HTML label, as this has a target to a control you'd think it would do something with it.
Paul
@Paul: At its simplest the label provides visual feedback when there is a validation error on the data to which the target is bound. In addition it can determine if the target is bound to a property that is marked as required using `DataAnnotations` `Required` attribute.
AnthonyWJones
Ahh yes I see it now.. Thanks for taking the time to explain it.
Paul