有了围绕控件的所有样式信息,以及嵌套的内容、控件模板和触发器,我试图弄清楚以下内容。
采用组合框控件。它有一个用于切换按钮组件的控制模板,该模板以标准显示(非下拉模式)显示正常显示,显示显示值和切换按钮以激活下拉菜单。
<ControlTemplate TargetType="ToggleButton" x:Key="baseComboBoxToggleButton" >
<!-- overall border covering left side display value and the actual toggle button -->
<Border x:Name="Border" Grid.ColumnSpan="2" />
<!-- area in left side (column=0) that shows the DISPLAY value -->
<Border x:Name="ShowDisplayValueArea" Grid.Column="0" />
<!-- second column using a path to draw the glyph down arrow -->
<Path Grid.Column="1" />
<Triggers for the toggle button ... />
</ControlTemplate>
然后,您拥有使用上面切换按钮模板的主组合框控件
<ControlTemplate TargetType="ComboBox" x:Key="ComboBoxGridControlTemplate" >
<Grid>
<ToggleButton Name="ToggleButton"
Template="{StaticResource baseComboBoxToggleButton}"
... />
</Grid>
</ControlTemplate>
因此,我试图根据 MultiBinding 转换器的结果最终更改“ShowDisplayValueArea”的背景颜色。如果我将多绑定转换器放在 toggleButton 控件模板区域中,例如..
<MultiBinding Converter="{StaticResource myMultiParmConverter}">
<Binding Path="." RelativeSource="{RelativeSource Self}" />
</MultiBinding>
值对象数组中的第一个“值”正确地传递了切换按钮控件模板的实例。整个对象引用,而不仅仅是名称。
public object Convert(object[] values,
Type targetType,
object parameter,
CultureInfo culture)
所以,我如何告诉 Binding 参数传递切换按钮来自的实际组合框(即:切换按钮的父级),所以我得到了作为参数传递的实际整个组合框控件。