I'm trying to replicate the Style
of DataGridComboBoxColumn's
TextBlockComboBox
. This is the control used by the DataGridComboBoxColumn
when the column's cells are not being edited. I was able to find out about this control by viewing the source at referencesource.microsoft.com (I would attempt to link directly to the type in question, but the browser on my work laptop has a security plugin that mangles URLs). Here is a snippet from that source:
internal class TextBlockComboBox : ComboBox
{
static TextBlockComboBox()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(TextBlockComboBox), new FrameworkPropertyMetadata(DataGridComboBoxColumn.TextBlockComboBoxStyleKey));
KeyboardNavigation.IsTabStopProperty.OverrideMetadata(typeof(TextBlockComboBox), new FrameworkPropertyMetadata(false));
}
}
/// <summary>
/// Style key for TextBlockComboBox
/// </summary>
public static ComponentResourceKey TextBlockComboBoxStyleKey
{
get
{
return SystemResourceKey.DataGridComboBoxColumnTextBlockComboBoxStyleKey;
}
}
From this snippet, you can see that the Style
for this control has it's key defined in SystemResourceKey.DataGridComboBoxColumnTextBlockComboBoxStyleKey
. I would like to copy this Style
in order to make additions and modifications in my own codebase. I can't seem to find the Style
that this key referes to, however. I tried duplicating the control (since it is an internal type) and using the Visual Studio Designer's Edit Template feature to get a generated copy of the Style/Template
, but all I got was the default ComboBox
Template
. From there, I tried simply using this default ComboBox
Style
and trying to modify it until it resembled the Style
of the TextBlockComboBox
, but that's just causing problems.
Does anybody know how to determine what is defined in the Style
for the key SystemResourceKey.DataGridComboBoxColumnTextBlockComboBoxStyleKey
?
Here is how it's defined in PresentationFramework.Aero2.dll
on Windows 8 and later:
<Style x:Key="{x:Static DataGridComboBoxColumn.TextBlockComboBoxStyleKey}" TargetType="{x:Type ComboBox}">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ComboBox}">
<ContentPresenter Margin="1,1,1,1" Content="{TemplateBinding ComboBox.SelectionBoxItem}"
ContentTemplate="{TemplateBinding ComboBox.SelectionBoxItemTemplate}"
ContentTemplateSelector="{TemplateBinding ItemsControl.ItemTemplateSelector}"
ContentStringFormat="{TemplateBinding ComboBox.SelectionBoxItemStringFormat}"
VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}"
HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}"
SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" IsHitTestVisible="false"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>