ListBox에서 상속받은 클래스와 ListBoxItems에 대한 사용자 지정 ControlTemplate이 있습니다. 조건이 true이면 ListBoxItems 배경을 변경하려고합니다. 나는 이것을 위해 DataTrigger를 사용하려고 시도했다. ListBoxItems 컨텍스트 개체의 조건을 확인하고 싶지 않습니다. 상속 된 ListBox 클래스에서 확인하고 싶습니다.사용자 지정 템플릿이있는 listboxitem 트리거가 목록 상자에 바인딩
질문은 어떻게 런타임에 각 ListBoxItem에 대한 올바른 값을 결정해야 할 때 ControlTemplate을 트리거로 ListBox 속성에 바인딩 할 수 있습니까? 좋아, 먼저 몇 가지 제안
<Style x:Key="ListBoxItemStyle" TargetType="ListBoxItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<Border Name="bd">
<TextBlock Name="lbl" Text="{Binding Path=DataChar}" FontWeight="ExtraBold" FontSize="15" Margin="5"/>
</Border>
<ControlTemplate.Triggers>
<DataTrigger Binding="{Binding RelativeSource={ RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBox}}, Path=IsSymbolExists}" Value="True">
<Setter TargetName="bd" Property="Background" Value="Yellow" />
</DataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
public class CustomListBox : ListBox
{
...
public bool IsSymbolExists
{
if(/*condition is true for the ListBoxItem*/)
return true;
return false;
}
}