将焦点设置在内容模板

时间:2016-02-26 14:51:53

标签: wpf xaml

我有一个单元格网格中单元格的内容模板。

 <DataTemplate x:Key="CellTemplate-TimeMode" >
    <Grid x:Name="grid1" SnapsToDevicePixels="True" Margin="0"  >
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="1*" />
                        <ColumnDefinition Width="1*" />
                    </Grid.ColumnDefinitions>
                    <!--Time editor textbox for start time-->
                    <TextBox Name="StartTimeText"
                             Grid.Column="0"
                             IsEnabled="{Binding IsAssignable}"
                             BorderThickness="0 0 1 0"
                             BorderBrush="{StaticResource   
                        GangAssignmentBorderBrush}"
 ...................................................................
 ..............................                         
                </Grid>
    <DataTemplate.Triggers>
        <Trigger SourceName="grid1" Property="IsFocused" Value="True">
            <Setter TargetName="StartTimeText"  
   Property="FocusManager.FocusedElement" Value="{Binding 
       ElementName=StartTimeText}" />
        </Trigger>
    </DataTemplate.Triggers>
   </DataTemplate>

这里引用

 <Grid  >
        <ContentControl x:Name="CellTemplateContainer" Content="{Binding}" >
                    <ContentControl.Style>
                        <Style  TargetType="ContentControl">
                            <Setter Property="ContentTemplate" Value="
                {StaticResource CellTemplate-BoxMode}" />

                             <Style.Triggers>

                                <DataTrigger Binding="{Binding ViewMode}" 
                                      Value="TimeMode">
                                    <Setter Property="ContentTemplate" 
                             Value="{StaticResource CellTemplate-TimeMode}"                                    
                       </Style.Triggers>
                        </Style>
                    </ContentControl.Style>
                </ContentControl>
                <!-- set a button layer on top of it (transparent) -->
                <ToggleButton  />

togglebutton是内容控件顶部的透明按钮。

我必须将焦点设置到文本框&#34; starttimetext&#34;在内容模板中&#34; CellTemplate-TimeMode&#34;当鼠标双击在单元格上时......我目前无法进行此操作。

有什么想法吗?

0 个答案:

没有答案