我有一個控制,具有依賴屬性「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