首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Telerik Tile背景绑定

Telerik Tile背景绑定
EN

Stack Overflow用户
提问于 2013-09-19 04:02:11
回答 2查看 1.2K关注 0票数 1

我试图在RadTileList中绑定Tile的背景,Tiles是从RadTileList的Itemsource上的集合创建的,到目前为止,我已经尝试更改Datatemplate中边框容器上的背景,但是Tile背景属性似乎正在解决这个问题。

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

注意:背景的颜色是使用转换器的字符串var so im,我是独立测试的。

代码语言:javascript
复制
    <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>
EN

回答 2

Stack Overflow用户

发布于 2013-10-23 14:12:34

创建一个以Tile为目标类型的分离样式。然后,您只需要设置背景属性。或者,您可以为样式命名并在RadTileList上显式设置它。

代码语言:javascript
复制
<UserControl.Resources>
    <ResourceDictionary>
    <Style TargetType="telerik:Tile" BasedOn="{StaticResource TileStyle}">
            <Setter Property="Background" Value="{StaticResource OmegaMainColorBrush}" />
        </Style>
    </ResourceDictionary>
</UserControl.Resources>
票数 0
EN

Stack Overflow用户

发布于 2016-04-07 08:09:26

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

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

代码语言:javascript
复制
    <Style TargetType="telerik:Tile" BasedOn="{StaticResource {x:Type telerik:Tile}}">
                    <Setter Property="flowConfiguration:TileAttachedProperties.IsTyleTypeBound" Value="True"/>
                    </Setter>

附加的属性代码(带有转换器)

代码语言:javascript
复制
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();
    }
}

的样子:

致以敬意,

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18885978

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档