1

我正在尝试将 Tile 的背景绑定在 a 中RadTileList,Tiles 是从 Itemsource 上的集合创建的RadTileList,到目前为止,我已经尝试在 中更改边框容器的背景Datatemplate,但似乎 Tile 背景属性正在赢得这一点。

在上面的代码中,我尝试设置ItemContainerStyle并设置背景绑定,但没有任何变化,希望有人能帮助我。

注意:背景的颜色是一个字符串变量,所以我使用转换器,我独立测试过

    <telerik:RadTileList ItemsSource="{Binding Modulo.Modulos_Detail}" TileReorderMode="None" 
                             ScrollViewer.HorizontalScrollBarVisibility="Visible">
            <telerik:RadTileList.ItemContainerStyle>
                <Style >
                    <Setter Property="telerik:Tile.TileType" Value="Quadruple" />
                    <Setter Property="telerik:Tile.Background" Value="{Binding .Color, Converter={StaticResource strHexColorConverter}}" />
                </Style>
            </telerik:RadTileList.ItemContainerStyle>
                <telerik:RadTileList.ItemTemplate>
                <DataTemplate>
                    <Border >
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="*" />
                                <RowDefinition Height="Auto" />
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition/>
                            </Grid.ColumnDefinitions>
                            <Image Grid.Row="0"
                                   HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                                   Source="{Binding .Imagenes.Imagen}" Stretch="Uniform"></Image>
                            <TextBlock Grid.Row="1"  Padding="5"
                                   Text="{Binding Descripcion}" FontSize="20" TextWrapping="Wrap" 
                                   VerticalAlignment="Bottom"/>
                            <!--<Image Source="{Binding .LockViewImage, Converter={StaticResource imgBitmapImageConverter}}" />-->
                        </Grid>
                    </Border>
                </DataTemplate>
            </telerik:RadTileList.ItemTemplate>
4

2 回答 2

0

使用Tile作为目标类型创建单独的样式。然后你只需要设置Background属性。或者,您可以为样式命名并在 RadTileList 上显式设置它。

<UserControl.Resources>
    <ResourceDictionary>
    <Style TargetType="telerik:Tile" BasedOn="{StaticResource TileStyle}">
            <Setter Property="Background" Value="{StaticResource OmegaMainColorBrush}" />
        </Style>
    </ResourceDictionary>
</UserControl.Resources>
于 2013-10-23T14:12:34.800 回答
0

在我看来,您可以在 Telerik:Tile 控件样式中使用布尔附加属性。如果该属性为 True,那么您将在后面的代码中创建绑定。您应该关心的唯一一件事是 Tile 的 Content 将保存 .Color 在那里定义的对象。这是代码。

样式(将其放入资源部分)

    <Style TargetType="telerik:Tile" BasedOn="{StaticResource {x:Type telerik:Tile}}">
                    <Setter Property="flowConfiguration:TileAttachedProperties.IsTyleTypeBound" Value="True"/>
                    </Setter>

随附的物业代码(带转换器)

public class TileAttachedProperties
{
    public static readonly DependencyProperty IsTyleTypeBoundProperty = DependencyProperty.RegisterAttached(
        "IsTyleTypeBound",
        typeof (bool),
        typeof (TileAttachedProperties),
        new PropertyMetadata(default(bool), IsTyleBoundPropertyChangedCallback));

    private static void IsTyleBoundPropertyChangedCallback(DependencyObject sender, DependencyPropertyChangedEventArgs args)
    {
        var tile = sender as Tile;
        var isBound = (bool) args.NewValue;
        if(tile == null || isBound == false) return;
        tile.Loaded += TileOnLoaded;
    }

    private static void TileOnLoaded(object sender, RoutedEventArgs routedEventArgs)
    {
        var tile = sender as Tile;
        if (tile == null) return;
        tile.Loaded -= TileOnLoaded;

        var tileContent = tile.Content;
        if (tileContent == null || tileContent is ItemTypeWrapper == false) return;

        //here we create binding to define if the type of the Tile(single or double)
        var tileTypeBinding = new Binding("IsDouble");
        tileTypeBinding.Source = tileContent;
        tileTypeBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
        tileTypeBinding.Converter = new Bool2TileTypeConverter();
        tile.SetBinding(Tile.TileTypeProperty, tileTypeBinding);

        //here we create binding to define the background of the tile
        var tileBackgroundBinding = new Binding("IsDouble");
        tileBackgroundBinding.Source = tileContent;
        tileBackgroundBinding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
        tileBackgroundBinding.Converter = new Bool2BackgroundConverter();
        tile.SetBinding(Tile.BackgroundProperty, tileBackgroundBinding);

    }

    public static void SetIsTyleTypeBound(DependencyObject element, bool value)
    {
        element.SetValue(IsTyleTypeBoundProperty, value);
    }

    public static bool GetIsTyleTypeBound(DependencyObject element)
    {
        return (bool) element.GetValue(IsTyleTypeBoundProperty);
    } 
}

internal class Bool2BackgroundConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        var isDouble = (bool)value;
        return isDouble ? new SolidColorBrush(Color.FromArgb(255, 255, 0, 255)) : new SolidColorBrush(Color.FromArgb(255,0, 255, 255));
    }

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

internal class Bool2TileTypeConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        var isDouble = (bool) value;
        return isDouble ? TileType.Double : TileType.Single;
    }

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

它的样子: 这里

问候,

于 2016-04-07T08:09:26.503 回答