1
道歉,如果這個問題的答案是完全明顯的,但它目前我難住。爲什麼這個例子中的文本框沒有獲得焦點?如果我使用沒有控制模板的香草文本框,焦點工作正常。控制模板文本框焦點
<StackPanel>
<Label Name="lblChartTitle"
Content="{x:Static res:Strings.ChartOptionsTitlesControlView_Label_Title}" />
<TextBox Name="txtChartTitle"
Text="{Binding Path=ChartTitle}"
MaxLength="255"
KeyboardNavigation.TabIndex="1"
Template="{DynamicResource ctTextBox3DInset}"
/>
<Label Name="lblChartCategoryXAxis"
Content="{x:Static res:Strings.ChartOptionsTitlesControlView_Label_CategoryXAxis}" />
<TextBox Name="txtChartCategoryXAxis"
Text="{Binding Path=CategoryXAxis}"
MaxLength="255"
KeyboardNavigation.TabIndex="2"
Template="{DynamicResource ctTextBox3DInset}"
/>
<Label Name="lblChartValueYAxis"
Content="{x:Static res:Strings.ChartOptionsTitlesControlView_Label_ValueYAxis}" />
<TextBox Name="txtChartValueYAxis"
Text="{Binding Path=ValueYAxis}"
MaxLength="255"
KeyboardNavigation.TabIndex="3"
Template="{DynamicResource ctTextBox3DInset}"
/>
</StackPanel>
<ControlTemplate x:Key="ctTextBox3DInset" TargetType="TextBox">
<Border
Style="{StaticResource BorderStyle3DInsetBlack}"
Margin="0,0,0,5">
<Border Style="{StaticResource BorderStyle3DInsetWhite}">
<Border Style="{StaticResource BorderStyle3DInset}">
<TextBox
TabIndex="{TemplateBinding TabIndex}"
BorderThickness="0"/>
</Border>
</Border>
</Border>
</ControlTemplate>
感謝您的回答。我正在使用.NET 3.5,我無法找到ControlPresenter。你的意思是ContentPresenter? – dior001 2012-02-16 15:05:17
Woops,對我的錯字感到抱歉。是的,我的意思是。 – 2012-02-16 15:06:34