1
我有一個「播放列表」,我想強調的「正在播放」項。WPF列表框DataTrigger不火
我想這
<!-- Row 5: Playlist -->
<ListBox x:Name="Tracks" MinHeight="400" Grid.Row="5" Margin="20">
<ListBox.ItemTemplate>
<DataTemplate>
<DockPanel Height="44" Width="436" Dock="Left">
<StackPanel Orientation="Vertical" Width="374" Name="Wrapper">
<Label Content="{Binding Path=title}" Name="Test" Foreground="CornflowerBlue" FontSize="14" Padding="0" />
<Label Content="{Binding Path=artist}" Foreground="DarkGray" FontSize="14" Padding="0" />
</StackPanel>
<Label Content="{Binding Path=DurationFormatted}" Foreground="DarkGray" Width="62" Padding="0" DockPanel.Dock="Right" HorizontalContentAlignment="Right" />
</DockPanel>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Path=NowPlaying}" Value="True">
<Setter TargetName="Wrapper" Property="Background" Value="LightBlue"/>
<Setter TargetName="Test" Property="FontSize" Value="24"/>
<Setter Property="ListBoxItem.Foreground" Value="Red" />
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
這
<ListBox.ItemTemplate>
same stuff without Triggers section
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=NowPlaying}" Value="True">
<Setter Property="ListBoxItem.Background" Value="Red" />
</DataTrigger>
</Style.Triggers>
</Style>
</ListBox.ItemContainerStyle>
NowPlaying只是音頻模型中的布爾屬性,我在調試器,當前的對象確實得到NowPlaying ==真檢查。但是這兩個觸發器都不會改變項目外觀。我做錯了什麼? 此外,對於我來說,我更喜歡命令式的風格。從代碼隱藏這樣做很容易嗎?
P.S.我爲測試設置了強調項目的極端值:)
謝謝,我不知道INotifyPropertyChanged的。 – Tommi 2013-03-26 12:29:02