开发者

Silverlight, itemcontrol LostFocus and GetFocus not firing

Okay, so the situation as like this:

I've got an ItemsControl, which contains several children.

the children are actually a UserControl, this is it's Xaml:

<Grid>
    <Grid.RowDefinitions>
         <RowDefinition Height="Auto" />
         <RowDefinition Height="*" />
    </Grid.RowDefinitions>

    <!--DAY HEADER-->
    <Border x:Name="dayHeader" Height="20" BorderBrush="#B0B6BE" BorderThickness="1" Grid.Row="0" Background="{StaticResource WeekHeader}">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>

            <TextBlock  Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Center" TextAlignment="Center"
                         TextWrapping="NoWrap" Margin="1.5,0,0,0" Text="18"/>

             <TextBlock  Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" TextAlignment="Center"
                         TextWrapping="NoWrap" Margin="2,0,0,0" Text="Thuesday" />
            </Grid>
    </Border>

    <!--DAY HOURS-->
    <ItemsControl x:Name="dayHours" Grid.Row="1">
         <ItemsControl.ItemTemplate>
              <DataTemplate>
                   <Border Name="dayHourBorder" Height="30" BorderBrush="#B0B6BE" Width="193" Tag="{Binding Index}" BorderThickness="1,0,1,1" Background="AliceBlue"
                                开发者_开发知识库            MouseLeftButtonDown="dayHourBorder_MouseLeftButtonDown" MouseLeftButtonUp="dayHourBorder_MouseLeftButtonUp"
                                                MouseMove="dayHourBorder_MouseMove" />

              </DataTemplate>
         </ItemsControl.ItemTemplate>
    </ItemsControl>
  </Grid>

IN SHORT it's a grid that in the first row has a border and in the second row has an ItemsControl.

Alright now... what i wanna do is, whenever i click between the child ItemControls (day hours) i want them to execute some function on the LostFocus() event and on GotFocus() event.

problem is... they don't fire! and it tried registering to them from every possible angle! HALP.

UPDATE I tried executing Focus() on MouseLeftButtonDown, but what happened is, it went straight to OnLostFocus, which is not what i want... i don't understand it


Here is an overview on focus in Silverlight. The article mentions four conditions that need to be satisfied in order for the control to get focus. You should check those four conditions for your control and it should be fine I suppose.

You should also consider on which element you'd like to receive those events as GotFocus and LostFocus are bubbling events.


I've managed to fix this issue by doing this: doing: this.Focus(); and then: e.Handled = true;

the problem was that the ItemControl usually can't hold focus, and so the click event bubbles up. but when i tell him it's Handled, it stops it's bubbling and won't lose the focus.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜