テーマテンプレートをClassicに設定するとコンボコントロールの前景色が正しく表示されない場合がある
対象製品
InputMan for WPF 1.0J
状況
修正済み
詳細
コンボコントロールを以下のように設定すると、コントロールにフォーカスを移動しても前景色がHighlightTextに変化しません。
- テーマテンプレートでClassicを設定する
- コンボコントロールのIsEditableプロパティをFalseに設定する
回避方法
この問題はService Pack 6(v1.0.2016.1130)で修正されました。
不具合を修正した最新のサービスパックは、アップデートページ からダウンロードできます。
Service Pack 6より前のバージョンでは、次の方法で回避可能です。
コンボコントロールのLoadedイベントに以下のコードを追加することで回避可能です。
[Visual Basic]
Private Sub GcComboBox1_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
Dim component As GcComboBox = TryCast(sender, GcComboBox)
Dim unEditableTemplate As ControlTemplate = component.UnEditableTemplate
If (Not unEditableTemplate Is Nothing) Then
Dim trigger As Trigger = Nothing
Dim trigger2 As Trigger
For Each trigger2 In unEditableTemplate.Triggers
If ((Not trigger2 Is Nothing) AndAlso (trigger2.Property Is GcComboBox.IsSelectionBoxHighlightedProperty)) Then
trigger = trigger2
Exit For
End If
Next
If ((Not trigger Is Nothing) AndAlso (trigger.Setters.Count = 1)) Then
Dim setter As Setter = TryCast(trigger.Setters.Item(0), Setter)
If ((Not setter Is Nothing) AndAlso ((setter.TargetName = "SelectedItemBorder") AndAlso ((setter.Value Is SystemColors.HighlightBrush) OrElse (TryCast(setter.Value, DynamicResourceExtension).ResourceKey Is SystemColors.HighlightBrushKey)))) Then
Dim descriptor As PropertyDescriptor = TypeDescriptor.GetProperties(component).Item("IsSelectionBoxHighlighted")
If (Not descriptor Is Nothing) Then
descriptor.AddValueChanged(component, Sub(senderObj, evt)
TryCast(senderObj, GcComboBox).Foreground = If(TryCast(senderObj, GcComboBox).IsSelectionBoxHighlighted, SystemColors.HighlightTextBrush, SystemColors.ControlTextBrush)
End Sub)
End If
End If
End If
End If
End Sub
[C#]
private void GcComboBox1_Loaded(object sender, RoutedEventArgs e)
{
var gcComboBox = sender as GcComboBox;
var comboBoxUneditableTemplate = gcComboBox.UnEditableTemplate;
if (comboBoxUneditableTemplate == null)
{
return;
}
Trigger trigger = null;
foreach (Trigger t in comboBoxUneditableTemplate.Triggers)
{
if (t != null)
{
if (t.Property == GcComboBox.IsSelectionBoxHighlightedProperty)
{
trigger = t;
break;
}
}
}
if (trigger == null)
{
return;
}
if (trigger.Setters.Count != 1)
{
return;
}
var setter = trigger.Setters[0] as Setter;
if (setter == null)
{
return;
}
if (setter.TargetName == "SelectedItemBorder" && (setter.Value == SystemColors.HighlightBrush || (setter.Value as DynamicResourceExtension).ResourceKey == SystemColors.HighlightBrushKey))
{
PropertyDescriptor pd = TypeDescriptor.GetProperties(gcComboBox)["IsSelectionBoxHighlighted"];
if (pd != null)
{
pd.AddValueChanged(gcComboBox, (senderObj, evt) => { (senderObj as GcComboBox).Foreground = (senderObj as GcComboBox).IsSelectionBoxHighlighted ? SystemColors.HighlightTextBrush : SystemColors.ControlTextBrush; });
}
}
}
不具合を修正した最新のサービスパックは、アップデートページ からダウンロードできます。
Service Pack 6より前のバージョンでは、次の方法で回避可能です。
コンボコントロールのLoadedイベントに以下のコードを追加することで回避可能です。
[Visual Basic]
Private Sub GcComboBox1_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
Dim component As GcComboBox = TryCast(sender, GcComboBox)
Dim unEditableTemplate As ControlTemplate = component.UnEditableTemplate
If (Not unEditableTemplate Is Nothing) Then
Dim trigger As Trigger = Nothing
Dim trigger2 As Trigger
For Each trigger2 In unEditableTemplate.Triggers
If ((Not trigger2 Is Nothing) AndAlso (trigger2.Property Is GcComboBox.IsSelectionBoxHighlightedProperty)) Then
trigger = trigger2
Exit For
End If
Next
If ((Not trigger Is Nothing) AndAlso (trigger.Setters.Count = 1)) Then
Dim setter As Setter = TryCast(trigger.Setters.Item(0), Setter)
If ((Not setter Is Nothing) AndAlso ((setter.TargetName = "SelectedItemBorder") AndAlso ((setter.Value Is SystemColors.HighlightBrush) OrElse (TryCast(setter.Value, DynamicResourceExtension).ResourceKey Is SystemColors.HighlightBrushKey)))) Then
Dim descriptor As PropertyDescriptor = TypeDescriptor.GetProperties(component).Item("IsSelectionBoxHighlighted")
If (Not descriptor Is Nothing) Then
descriptor.AddValueChanged(component, Sub(senderObj, evt)
TryCast(senderObj, GcComboBox).Foreground = If(TryCast(senderObj, GcComboBox).IsSelectionBoxHighlighted, SystemColors.HighlightTextBrush, SystemColors.ControlTextBrush)
End Sub)
End If
End If
End If
End If
End Sub
[C#]
private void GcComboBox1_Loaded(object sender, RoutedEventArgs e)
{
var gcComboBox = sender as GcComboBox;
var comboBoxUneditableTemplate = gcComboBox.UnEditableTemplate;
if (comboBoxUneditableTemplate == null)
{
return;
}
Trigger trigger = null;
foreach (Trigger t in comboBoxUneditableTemplate.Triggers)
{
if (t != null)
{
if (t.Property == GcComboBox.IsSelectionBoxHighlightedProperty)
{
trigger = t;
break;
}
}
}
if (trigger == null)
{
return;
}
if (trigger.Setters.Count != 1)
{
return;
}
var setter = trigger.Setters[0] as Setter;
if (setter == null)
{
return;
}
if (setter.TargetName == "SelectedItemBorder" && (setter.Value == SystemColors.HighlightBrush || (setter.Value as DynamicResourceExtension).ResourceKey == SystemColors.HighlightBrushKey))
{
PropertyDescriptor pd = TypeDescriptor.GetProperties(gcComboBox)["IsSelectionBoxHighlighted"];
if (pd != null)
{
pd.AddValueChanged(gcComboBox, (senderObj, evt) => { (senderObj as GcComboBox).Foreground = (senderObj as GcComboBox).IsSelectionBoxHighlighted ? SystemColors.HighlightTextBrush : SystemColors.ControlTextBrush; });
}
}
}