我正在尝试在Windows Phone 8上使用颜色选择器,但我看不到颜色。我不明白我在哪里弄错了。
这是我的数据透视表代码:
string[] colorNames =
{
"GreenYellow","Lime","Chartreuse","LimeGreen","SpringGreen","LightGreen"
}
uint[] uintColors =
{
0xFFFFFF00,0xFFFFE135,0xFFFFFF66,0xFFF8DE7E,0xFF008000,0xFF008A00
}
List<ColorItem> item = new List<ColorItem>();
for (int i = 0; i < 6; i++)
{
item.Add(new ColorItem() { Text = colorNames[i], Color = ConvertColor(uintColors[i]) });
};
listPicker.ItemsSource = item; //Fill ItemSource with all colors
}
private Color ConvertColor(uint p)
{
byte A = (byte)((p & 0xFF000000) >> 24);
byte R = (byte)((p & 0x00FF0000) >> 16);
byte G = (byte)((p & 0x0000FF00) >> 8);
byte B = (byte)((p & 0x000000FF) >> 0);
return Color.FromArgb(A, R, G, B); ;
}
这是我的ColorItem类:
class ColorItem
{
public string Text { get; set; }
public Color Color { get; set; }
}
像这样:
而且:
答案 0 :(得分:0)
你遗漏了实际构建彩色方块的xaml。见link
<phone:PhoneApplicationPage
x:Class="CustomColorsPicker.ColorPickerPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
mc:Ignorable="d"
shell:SystemTray.IsVisible="False"
xmlns:converters="clr-namespace:CustomColorsPicker.Converters"
xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
toolkit:TiltEffect.IsTiltEnabled="True">
<phone:PhoneApplicationPage.Resources>
<converters:ColorToBrushConverter x:Key="ColorToBrushConverter"/>
</phone:PhoneApplicationPage.Resources>
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<ListBox Name="listBox" SelectionChanged="lstColor_SelectionChanged">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<toolkit:WrapPanel/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel x:Name="item" Orientation="Horizontal" Margin="12, 6 0, 6">
<Rectangle Fill="{Binding Color, Converter={StaticResource ColorToBrushConverter}}"
Width="100" Height="100" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</Grid>
</phone:PhoneApplicationPage>