Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用IValueConverter WPF对自动生成的列单元格进行着色_Wpf_Vb.net_Binding - Fatal编程技术网

使用IValueConverter WPF对自动生成的列单元格进行着色

使用IValueConverter WPF对自动生成的列单元格进行着色,wpf,vb.net,binding,Wpf,Vb.net,Binding,我想问您是否可以使用转换器更改自动生成的柱状单元格颜色 我的xaml数据网格: <DataGrid ItemsSource="{Binding FillDG}" x:Name="ListHoliday" HorizontalAlignment="Left" Height="186" VerticalAlignment="Top" Width="880" Grid.Column="1" Margin="10.4,103,0,0" Grid.Row="1"/> 但我不知道如何将其绑

我想问您是否可以使用转换器更改自动生成的柱状单元格颜色

我的xaml数据网格:

<DataGrid ItemsSource="{Binding FillDG}" x:Name="ListHoliday" 
HorizontalAlignment="Left" Height="186" VerticalAlignment="Top" 
Width="880" Grid.Column="1" Margin="10.4,103,0,0" Grid.Row="1"/>
但我不知道如何将其绑定到每个自动生成的日期单元格/列。
非常感谢您的建议

您可以设置DataGrid的
CellStyle
,它将由自动生成的列单元格拾取

<DataGrid>
   <DataGrid.CellStyle>
      <Style TargetType="DataGridCell">
        <Setter Property="Background"
                Value="{Binding Converter={StaticResource ColorConverter}}"/>
      </Style>
</DataGrid.CellStyle>
</DataGrid>

您可以通过将样式应用于生成的DataGridTextColumn来实现。是的,我尝试使用:“”和:“”-没有任何结果…它可以工作,但这是整排的颜色。我想我必须以某种方式给他那些日期列的名称……您可以将
传递给转换器,并将代码放入其中。请参阅答案中的更新。非常感谢。嗯,因此,如果在我的代码中,日期为c1的自动生成列,我应该将该c1('Dim c1作为新的DataGridTextColumn c1.Header=Format(currentDate,“MMMM”)&vbCrLf&Formattedd ListHoliday.Columns.Add(c1)'传递为“”列**到转换器?是的,如果您对该列感兴趣或不感兴趣,您可以签入转换器。我在转换器中调用该列:Dim V As SolidColorBrush=Brush。白色Dim holi As New HolidayLog Dim drv As DataRowView=TryCast(value,DataRowView)Dim Column As DataGridTextColumn=TryCast(holi.DateCol,DataGridTextColumn)如果drv不为空,则将dt调整为String=String.Format(drv(“HType”).ToString)如果dt=“假期”,则列不为空,则V=画笔。如果结束,则蓝色结束,如果结束,则返回V,但单元格为空。
Dim V As SolidColorBrush = Brushes.White
Dim holi As New HolidayLog
For Each hitem As DataRowView In holi.dgMyTeamView.ItemsSource
    Dim hType As String = hitem.Item("HType")
    If hType.Trim() = "Vacation" Then
    V = Brushes.Blue
    End If
Next
Return V
<DataGrid>
   <DataGrid.CellStyle>
      <Style TargetType="DataGridCell">
        <Setter Property="Background"
                Value="{Binding Converter={StaticResource ColorConverter}}"/>
      </Style>
</DataGrid.CellStyle>
</DataGrid>
<DataGrid>
    <DataGrid.CellStyle>
        <Style TargetType="DataGridCell">
            <Setter Property="Background"
                    Value="{Binding Column,
                                    RelativeSource={RelativeSource Self}, 
                                    Converter={StaticResource ColorConverter}}"/>
        </Style>
    </DataGrid.CellStyle>
</DataGrid>
DataGridColumn column = value as DataGridColumn;

 // Check for property name here.
if (column != null && column.Header.ToString() == "Name")
{
    return Brushes.Blue;
}
return Brushes.White;