Hi,
I have placed a button inside XamTabControl.(See the screen shot below).
The xaml code for button is:
<Button Name="btnSearchLookUptype" Click="btnSearchLookUptype_Click">S_earch</Button>
I want the hot key for the button as "atl+e". Hence i place "_" before "e" in button text "Search". But as u can see in the screen shot, the text for button is being displayed as "S_earch" rather than "Search".
If the same is placed without the tab control then its working correctly.
So can you please tell me what the problem is and how it can be resolved?
Thanks & Regards,
Varun R
I tried this out and wasn't able to reproduce the issue. Is it possible that you have defined a DataTemplate for string that uses a TextBlock somewhere in the ancestor chain of that button? If not, can you provide a sample that demonstrates the issue?
please find the below sample code for your reference.
<Grid Style="{StaticResource gridGrd}" Name="layoutRoot"> <igWindows:XamTabControl Name="xamTabLookUpType" igWindows:TabItemEx.Closed="tcLookUpType_Closed" TabItemCloseButtonVisibility="Visible" AllowMinimize="True" ShowTabHeaderCloseButton="True" TabLayoutStyle="MultiRowAutoSize"> <igWindows:XamTabControl.Resources> <Style TargetType="{x:Type igWindows:TabItemEx}"> <Style.Resources> <DataTemplate DataType="{x:Type sys:String}"> <TextBlock VerticalAlignment="Center" Text="{Binding}"/> </DataTemplate> </Style.Resources> <Setter Property="HeaderTemplate"> <Setter.Value> <DataTemplate DataType="{x:Type igWindows:TabItemEx}"> <Grid Margin="2"> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> <ColumnDefinition Width="*"/> </Grid.ColumnDefinitions> <Border BorderThickness="1" CornerRadius="3" BorderBrush="Purple" Margin="1"> <Image Margin="2" Width="10" Height="10" Source="{Binding Mode=TwoWay, Path=Tag, RelativeSource={RelativeSource AncestorType={x:Type igWindows:TabItemEx}}}"/> </Border> <ContentControl Content="{TemplateBinding Content}" Grid.Column="1" Margin="6,0,0,0"/> </Grid> </DataTemplate> </Setter.Value> </Setter> </Style> </igWindows:XamTabControl.Resources> <igWindows:TabItemEx Header="Look Up Types" AllowClosing="False" HorizontalAlignment="Left" > <Grid> <Grid.RowDefinitions> <RowDefinition></RowDefinition> <RowDefinition Height="10"></RowDefinition> <RowDefinition></RowDefinition> <RowDefinition></RowDefinition> </Grid.RowDefinitions> <Grid Height="Auto" VerticalAlignment="Top"> <Grid.ColumnDefinitions> <ColumnDefinition /> <ColumnDefinition /> <ColumnDefinition /> <ColumnDefinition /> <ColumnDefinition /> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="10"></RowDefinition> <RowDefinition></RowDefinition> <RowDefinition></RowDefinition> <RowDefinition Height="10"></RowDefinition> </Grid.RowDefinitions> <Label Name="lblLookUpTypeName" Grid.Row="1" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Right" TabIndex="1" Style="{StaticResource labellDefault}">Look Up Type Name:</Label> <TextBox Name="txtLookUpTypeName" Grid.Row="1" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Left" Width="180" TabIndex="2" MaxLength="10" ToolTip="Enter Look Up Type Name to Search" Style="{StaticResource txtBoxDefault}" ></TextBox> <Label Name="lblLookUpTypeDesc" Grid.Row="1" Grid.Column="2" VerticalAlignment="Center" HorizontalAlignment="Right" TabIndex="3">Look Up Type Description:</Label> <TextBox Name="txtLookUpTypeDesc" Grid.Row="1" Grid.Column="3" VerticalAlignment="Center" HorizontalAlignment="Left" Width="180" TabIndex="4" MaxLength="10" ToolTip="Enter Look Up Type Description to Search" Style="{StaticResource txtBoxDefault}" ></TextBox> <Button Name="btnSearchLookUptype" Grid.Row="1" Grid.Column="4" Grid.ColumnSpan="1" VerticalAlignment="Center" HorizontalAlignment="Center" Width="80" TabIndex="5" ToolTip="Search Look Up Types" Style="{StaticResource buttonDefault}" Click="btnSearchLookUptype_Click">S_earch</Button> </Grid> </Grid> </igWindows:TabItemEx> </igWindows:XamTabControl> </Grid>
Thanks
Varun
So to answer my question to you based on your snippet - yes, you have a DataTemplate that targets the Type String and that just uses a TextBlock which is why you are seeing the "_" in the text. Basically the ContentPresenter within the Button is getting this DataTemplate (since the Content of a Tab is a logical child of the tab) and using that. This is correct based on the way you have this set up. I'm not sure what element you are trying to target with that DataTemplate but if its the Header of the TabItem then you should probably put that into the resouces of the DataTemplate you have defined for the HeaderTemplate. e.g.