Custom Background Converter for LongListSelector

I have a specific color scheme in my application, and I wan't my Jump LongListSelectorslist style exactly matches my color scheme, I created a style for JumpList and something like that.

<Style x:Name="LibraryJumpListStyle" TargetType="phone:LongListSelector">
    <Setter Property="ItemTemplate">
        <Setter.Value>
            <DataTemplate>
                <Border Background="#007fb3" Margin="6" toolkit:TiltEffect.IsTiltEnabled="True">
                    <TextBlock Text="{Binding Key}" FontFamily="{StaticResource PhoneFontFamilySemiBold}" FontSize="48" Margin="12,0,0,0" Foreground="White" VerticalAlignment="Bottom"/>
                </Border>
            </DataTemplate>
        </Setter.Value>
    </Setter>
    <Setter Property="LayoutMode" Value="Grid"/>
    <Setter Property="GridCellSize" Value="111,111"/>
    <Setter Property="Margin" Value="12,6,0,0"/>
</Style>

But this makes all of my jump list items, including disabled ones (sections in which I don't have items) the same color. I want disabled jumplist elements to be of different colors. I understand, for this I need to make my own BackgroundConverter. But the problem is that I do not know where to start or how. What parameters do I need to go through. I know how valuse converters work, and I wrote some converters. But here I do not know. I searched and did not find any example code where I can use as a base for my custom BackgroundConverter. Can anybody help?

+4
source share
2 answers

, , , ? ,

<phone:LongListSelector x:Name="accounts_ls" IsGroupingEnabled="True" HideEmptyGroups="true"/>

, ; , :

Change-the-background-of-a-border-with-converter

GroupKeyList , IsPair , (0), - .

0

.

using Windows.UI;
using Windows.UI.Xaml.Media;

public class ColorResolver : IValueConverter
{

    public object Convert(object value, Type targetType, object parameter, string language)
    {
       return GetColorFromHexa((string) value)); 
    }

    public object ConvertBack(object value, Type targetType, object parameter, string language)
    {
        throw new NotImplementedException();
    }

    private SolidColorBrush GetColorFromHexa(string hexaColor)
    {
        return new SolidColorBrush(
            Color.FromArgb(
                255,
                Convert.ToByte(hexaColor.Substring(1, 2), 16),
                Convert.ToByte(hexaColor.Substring(3, 2), 16),
                Convert.ToByte(hexaColor.Substring(5, 2), 16)
            )
        );
     }
}

, .

<Border Background="{Binding MyColorProperty, Converter={StaticResource MyColorConverter}}" Margin="6" toolkit:TiltEffect.IsTiltEnabled="True">
    <TextBlock Text="{Binding Key}" FontFamily="{StaticResource PhoneFontFamilySemiBold}" FontSize="48" Margin="12,0,0,0" Foreground="White" VerticalAlignment="Bottom"/>
</Border>

WinRT. GetColorFromHexa() WP8 . . . !:)

0

All Articles