我想在WPF中爲聊天Messenger創建一個自定義列表框控件。我使用橢圓顯示在線/離線用戶。橢圓將顯示在左側,並且一些文本位於ListBoxItem的中央。WPF中的自定義列表框
我想根據某些變量將橢圓填充屬性設置爲紅色/綠色。
這是我做了什麼:
<ListBox Name="myList" HorizontalAlignment="Left" Height="232" Margin="117,74,0,0" VerticalAlignment="Top" Width="207">
<ListBox.ItemTemplate>
<DataTemplate>
<DockPanel>
<Ellipse Name="ellipse" Fill="Red" DockPanel.Dock="Left">
<Ellipse.Triggers>
<Trigger Property="{Binding Online}" Value="True">
<Setter TargetName="ellipse" Property="Ellipse.Fill" Value="Green"/>
</Trigger>
</Ellipse.Triggers>
</Ellipse>
<TextBlock Text="{Binding text}"></TextBlock>
</DockPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
,並在代碼:
myList.Items.Add(new { text="Hello",Online="True" });
我得到一個錯誤
Cannot find the static member 'FillProperty' on the type 'ContentPresenter'.
我在做什麼錯這裏?