开发者

silverlight datagrid multicontrol TemplateColumn TabIndex issue

In SL4 DataGrid I have the following multicontrol column:

<sdk:DataGridTemplateColumn Header="Address Line1&#x0a;Address Line 2" MinWidth="200">
  <sdk:DataGridTemplateColumn.CellTemplate>
    <DataTemplate>
      <StackPanel>
        <TextBlock Text="{Binding Path=Address1}"/>
        <TextBlock Text="{Binding Path=Address2}"/>
      </StackPanel>
    </DataTemplate>
  </sdk:DataGridTemplateColumn.CellTemplate>
  <sdk:DataGridTemplateColumn.CellEditingTemplate>
    <DataTemplate>
      <StackPanel>
        <TextBox Background="Transparent" BorderThickness="0" 
                 TabIndex="0"
                 Text="{Binding Path=Address1, Mode=TwoWay}"/>
        <TextBox Background="Transparent" BorderThickness="0" 
                 TabIndex="1"
                 Text="{Binding Path=Address2, Mode=TwoWay}"/>
      </StackPanel>
    </DataTemplate>
  </sdk:DataGridTemplateColumn.CellEditingTemplate>
</sdk:DataGridTemplateColumn>

In edit mode pressing Tab key while at address1 moves focus to next DataGrid column but not to address2 textbox. If I delete CellTemplate and CellEditingTemplate to be CellTemplate instead, then TabIndex works as expected, however, current column stay the same, so if datagrid has man开发者_如何学JAVAy columns, some of which are hidden, then auto scrolling doesn't occur. What should I do to solve this problem?


A little bit late, but i found a workaround for this problem.

Just add a KeyDown EventHandler to your CustomControl:

private void address1_KeyDown(object sender, KeyEventArgs e)
{
    if (e.Key.Equals(Key.Tab) && address2.IsEnabled)
    {
        address2.Focus();
        e.Handled = true;
    }
}


Probably, having multiple controls inside datagrid cell is bad idea. If multiple controls needs to be inside cell, then better way seems to be to create custom composite control and place it inside cell.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜