我有一个控制,具有依赖属性“IsLightOnVal”女巫是这样定义:绑定触发元素父集合的
// List of available states for this control
private ObservableCollection<CtlStateBool> m_IsLightOnVal;
[Category("Properties")]
public System.Collections.ObjectModel.ObservableCollection<CtlStateBool> IsLightOnVal
{
get
{
if (m_IsLightOnVal == null)
m_IsLightOnVal = new System.Collections.ObjectModel.ObservableCollection<CtlStateBool>();
return m_IsLightOnVal;
}
set
{
if (m_IsLightOnVal != value)
{
m_IsLightOnVal = value;
OnPropertyChanged("IsLightOnVal");
}
}
}
// IsLightOnVal dependency property.
public static readonly DependencyProperty IsLightOnValProperty =
DependencyProperty.Register("IsLightOnVal", typeof(System.Collections.ObjectModel.ObservableCollection<CtlStateBool>), typeof(ButtonSimple), new UIPropertyMetadata(new System.Collections.ObjectModel.ObservableCollection<CtlStateBool>()));
在我的收藏,每个元素包含一个字符串(州)和布尔(Value)
我的控件风格在ControlTemplate中定义。
我想添加一个触发器,例如,当我的集合中的第一个元素为true时,然后执行一些操作。
我尝试这样做:
<Style x:Key="Btn_RADIO_VHF" TargetType="{x:Type ButtonSimple}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ButtonSimple}">
<Canvas .../>
<ControlTemplate.Triggers>
<DataTrigger Value="True" Binding="{Binding IsLightOnVal[0].Value, RelativeSource={RelativeSource TemplatedParent}}">
<Setter Property="Fill" TargetName="pShowTouch" Value="{DynamicResource ShowTouch}"/>
</DataTrigger>
</ControlTemplate.Triggers>
我也试过用一个简单的触发器,而不是一个DataTrigger,但它似乎不支持绑定...
有人能帮助我吗?
谢谢,但我只是写了一个例子,我们的图形设计师将使用这个集合来添加他所需要的项目,然后他需要将它们绑定到图形上。因此,他可以通过更改集合中的值并保持始终相同的样式来重复使用相同样式的多个项目。 – mlemay 2012-07-23 14:41:25