Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.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
C# C中不同颜色的表格#_C#_Wpf_Silverlight_Colors - Fatal编程技术网

C# C中不同颜色的表格#

C# C中不同颜色的表格#,c#,wpf,silverlight,colors,C#,Wpf,Silverlight,Colors,我想要一张有各种颜色的桌子。随后的颜色应明显不同。根据这一点填充相当大的表的最佳方法是什么?在重复使用类似的颜色之前,我想使用大量不同的颜色。您可以在C#中使用Gridview,然后使用 GridView_RowDataBound(object sender, GridViewRowEventArgs e) 方法将单元格的背景颜色更改为所需的任何颜色 if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Cel

我想要一张有各种颜色的桌子。随后的颜色应明显不同。根据这一点填充相当大的表的最佳方法是什么?在重复使用类似的颜色之前,我想使用大量不同的颜色。

您可以在C#中使用Gridview,然后使用

GridView_RowDataBound(object sender, GridViewRowEventArgs e)
方法将单元格的背景颜色更改为所需的任何颜色

    if (e.Row.RowType == DataControlRowType.DataRow)
    {
    e.Row.Cells[4].BackColor = System.Drawing.Color.FromName("#EE3333"); // makes the 4th cell red
    e.Row.BackColor = System.Drawing.Color.ForestGreen; // Makes the whole row Green
    }
使用此方法,您可以使用RGB颜色为单元格着色

这是我的解决方案(与Silverlight兼容)

在MainPage.Xaml.cs构造函数中包含如下代码:-

    <ListBox ItemsSource="{Binding}">
        <ListBox.ItemTemplate>
            <DataTemplate>
                <Rectangle Width="200" Height="20" Fill="{Binding}" />
            </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
   DataContext = VaryingColors(0).Take(100).Select(c => new SolidColorBrush(c));
颜色生成器将生成所有1600万种可能的颜色,并首先操纵RGB分量的最高有效位。可能需要多做一点工作。虽然相邻颜色总是明显不同,但也有一些相邻颜色比序列中的其他颜色更相似


一个增强可能是在序列上添加一个过滤器,以丢弃太暗或饱和度非常低的颜色。事实上,可能会添加另一个过滤器,以丢弃色调接近序列中前一种颜色的颜色。

定义“大”,定义“显著不同”?大,例如1000种颜色。显著不同-我想得到例如红色、蓝色、绿色,而不是红色、深红色、紫色;-)简单地说,我想避免重复使用类似的颜色。我使用HSL/HSV颜色并将它们转换回RGB得到了很好的结果。您将SL/SV保持固定并通过H值。@xanatos,这正是我现在正在做的:-)但是我不能保证后续的颜色会有显著的不同。您如何选择后续的H值?@Jamie您将H空间细分为1000个部分。。。但是你的颜色太相似了。有1000种颜色足够复杂,你知道吗?对不起,我想你没有理解我的问题:-)
   DataContext = VaryingColors(0).Take(100).Select(c => new SolidColorBrush(c));