我有一個ViewModel,它包含一個布爾值的ObservableCollection。我有一個控制。 想要將我的布爾值列表可視化爲具有兩種不同顏色的矩形列表。 我無法聲明這種綁定。這裏是我的代碼:綁定:使用DataTemplate和綁定可視化未命名的布爾值列表
<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>
它的工作原理,臨屋區NKS。 –