【发布时间】:2011-05-04 18:19:14
【问题描述】:
我在列表框上有自己的样式,我在样式数据模板和控件模板中使用。 在数据模板中,我创建了带有一些文本框的列表框项。在控件模板中,我想创建一个触发器,如果选择了列表框项,该触发器会更改某些文本框的前景色。
以下是一些风格:
<Style x:Key="lbStyle" TargetType="{x:Type ListBox}">
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate>
<Grid Name="MainGrid">
<TextBlock Name="tbName" Text="{Binding Value.nick}"
Grid.Column="0" Grid.Row="0" Margin="2,2,2,2"
FontSize="13" FontWeight="Medium"></TextBlock>
</Grid>
</DataTemplate>
</Setter.Value>
</Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListBoxItem">
<ControlTemplate.Triggers>
<Trigger Property="IsSelected" Value="true">
<Setter TargetName="tbName" Property="Foreground" Value="Black"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
问题是,我得到编译错误:找不到触发器目标 tbName。
【问题讨论】:
标签: wpf xaml styles datatemplate controltemplate