Tôi đã có một số nguồn WPF:Hoạt ảnh WPF ném thuộc tính Ngoại lệ "'Nền" không trỏ đến DependencyObject trong đường dẫn' (0). (1) '. "
<Window x:Class="WpfApplication2.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<SolidColorBrush x:Key="RedBrush" Color="Red"/>
<SolidColorBrush x:Key="GreenBrush" Color="Green"/>
<SolidColorBrush x:Key="TransparentBrush" Color="Transparent"/>
<DataTemplate x:Key="MyItemTemplate">
<Grid Margin="5">
<Grid.ColumnDefinitions>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock Background="{DynamicResource TransparentBrush}">
<TextBlock.Style>
<Style>
<Style.Triggers>
<DataTrigger Binding="{Binding State}" Value="Stat1">
<Setter Property="TextBlock.Background" Value="{DynamicResource RedBrush}" />
</DataTrigger>
<DataTrigger Binding="{Binding State}" Value="Stat2">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard RepeatBehavior="Forever">
<ColorAnimation
Storyboard.TargetProperty="(TextBlock.Background).(SolidColorBrush.Color)"
Duration="00:00:01"
From="Yellow" To="Red"/>
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
<TextBlock.Text>
<Binding Path="Name" />
</TextBlock.Text>
</TextBlock>
</Grid>
</DataTemplate>
</Window.Resources>
<ListBox x:Name="SomeList"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Top"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ScrollViewer.VerticalScrollBarVisibility="Visible"
ItemTemplate="{StaticResource MyItemTemplate}">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="3" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
tôi điền vào danh sách với:
public MainWindow()
{
InitializeComponent();
myList_ = new List<Foo>();
myList_.Add(new Foo() { State = "Stat1", Name = "Name 1" });
myList_.Add(new Foo() { State = "Stat2", Name = "Name 2" });
SomeList.ItemsSource = myList_;
}
Vấn đề là, rằng tôi đã nhận một ngoại lệ 'nền' bất động sản không trỏ vào DependencyObject trong đường dẫn '(0). (1)'. Tôi không biết lý do tại sao :-(Có andybody biết?
Cảm ơn liên quan Michael
Tôi đã thử mọi thứ để chạy;) Bạn có thể đăng nguồn XAML không? Tôi không thể làm cho nó chạy :-(Cảm ơn – Michael
@Michael: Tôi đã thêm mã làm việc cho tôi. Hy vọng bạn có thể làm cho mã của bạn hoạt động. –