【发布时间】:2012-05-14 12:55:54
【问题描述】:
我有一个 ViewModel,它包含一个 ObservableCollection 的布尔值。而且我有控制权。 想要将我的布尔值列表可视化为具有两种不同颜色的矩形列表。 我不能声明这样的绑定。这是我的代码:
<UserControl.Resources>
<DataTemplate x:Key="DataTemplateName">
<Grid Margin="12,0,0,0">
<Rectangle Fill="{Binding ***PROBLEM***
, Converter={StaticResource BoolToSelectionBrushConverter}"}
HorizontalAlignment="Right"
Margin="0" Width="25"
Height="25" VerticalAlignment="Top"
StrokeThickness="0"/>
</Grid>
</DataTemplate>
</UserControl.Resources>
<Grid x:Name="LayoutRoot">
<ItemsControl
ItemsSource="{Binding Statuses}"
ItemTemplate="{StaticResource DataTemplateName}"
Margin="0,0,8,0">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
我可以在不创建包装器的情况下实现它吗?
public class Value
{
public bool IsOk{get;set;}
}
并绑定到命名属性:
<Grid Margin="12,0,0,0">
<Rectangle Fill="{Binding IsOk
, Converter={StaticResource BoolToSelectionBrushConverter}}"
HorizontalAlignment="Right"
Margin="0" Width="25"
Height="25" VerticalAlignment="Top"
StrokeThickness="0"/>
</Grid>
【问题讨论】:
标签: c# windows-phone-7 xaml data-binding