【发布时间】:2017-02-27 17:48:15
【问题描述】:
我需要创建一个与名称、布尔状态和颜色指定的项目绑定的列表。
这是我的 ViewModel:
using Caliburn.Micro;
public class MainWindowViewModel :Screen
{
private List<string> _commandListSource;
private List<CommandItem> _commandsSource;
public List<CommandItem> CommandsSource
{
get
{
return _commandsSource;
}
set
{
_commandsSource = value;
NotifyOfPropertyChange(() => CommandsSource);
}
}
public MainWindowViewModel()
{
_commandListSource = new List<string>();
_commandListSource.Add("A");
_commandListSource.Add("B");
getsource();
NotifyOfPropertyChange(() => CommandsSource);
}
private void getsource()
{
_commandsSource = new List<CommandItem>();
foreach (var x in _commandListSource)
{
var ci = new CommandItem();
ci.CommandName = x;
ci.IsInTheOtherList = true;
_commandsSource.Add(ci);
}
}
}
CommandItem类:
public class CommandItem
{
public string CommandName;
public bool IsInTheOtherList;
public Color BGColor
{
get
{
if (IsInTheOtherList)
return Color.FromRgb(0, 0,255);
return Color.FromRgb(255, 255,0);
}
}
}
XamlListBox:
<ListBox x:Name="Source"
ItemsSource="{Binding CommandsSource , NotifyOnSourceUpdated=True}"
HorizontalAlignment="Left"
ScrollViewer.VerticalScrollBarVisibility="Visible"
VerticalAlignment="Stretch" MinWidth="100">
<ListBox.ItemTemplate>
<DataTemplate>
<DockPanel >
<TextBlock Text="*"/>
<Ellipse Fill="{Binding BGColor}" Width="10" Height="10"/>
<TextBlock Text="{Binding CommandName}"/>
</DockPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
问题是ListBox 只显示* 字符
【问题讨论】:
标签: c# wpf mvvm listbox caliburn.micro