0
我有一個列表框定義爲:如何更改模板列表框中特定元素的樣式?
<ListBox ... ItemTemplate="{DynamicResource User}"/>
的ItemTemplate是:
<DataTemplate x:Key="User">
<DataTemplate.Resources>
<Style TargetType="{x:Type Border}" x:Key="Ordinal">
<Setter Property="Background">
<Setter.Value>
...
</Setter.Value>
</Setter>
</Style>
<Style TargetType="{x:Type Border}" x:Key="Current">
<Setter Property="Background">
<Setter.Value>
...
</Setter.Value>
</Setter>
</Style>
</DataTemplate.Resources>
<Border CornerRadius="5" Padding="5" Margin="0,0,5,0" Style="{StaticResource Ordinal}">
...
</Border>
</DataTemplate>
現在我有一個事件處理程序應當設置項目的風格,提供索引「當前」:
void SetCurrent(int Index)
{
?
}
如何做到這一點?
編輯:
也許使用的ItemsControl將簡化這個過程?
它應該用作DataTemplate的資源? – deha
作爲列表框資源我想 –