2013-09-19 2 views
1

Я пытаюсь связать фон плитки в RadTileList, плитки создаются из коллекции на Itemsource RadTileList, до сих пор я пытался изменить фон в контейнере границы в Datatemplate, но кажется, что свойство фона Tile выигрывает над этим.Telerik 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> 

ответ

0

Создать индивидуальный стиль с плитки как целевого типа. Тогда вам нужно установить только Фон. При желании вы можете присвоить стилю имя и установить его явно в RadTileList.

<UserControl.Resources> 
    <ResourceDictionary> 
    <Style TargetType="telerik:Tile" BasedOn="{StaticResource TileStyle}"> 
      <Setter Property="Background" Value="{StaticResource OmegaMainColorBrush}" /> 
     </Style> 
    </ResourceDictionary> 
</UserControl.Resources> 
0

По моему мнению, вы можете использовать логическое свойство Attached в telerik: стиль управления плиткой. Если это свойство True, вы создаете привязку в коде. Единственное, о чем вы должны заботиться, это то, что содержимое плитки будет содержать объект, который там определен .Color. Вот код.

Style (поместите это в часть ресурсов)

<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(); 
    } 
} 

Как это выглядит следующим образом: here

С уважением,

Смежные вопросы