<UserControl x:Class="InventoryView" xmlns:tools="ViewModels.Tools;assembly=ViewModels" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" xmlns:conv="clr-namespace:Views.Converters" xmlns:views="clr-namespace:Views" mc:Ignorable="d" d:DesignHeight="700" d:DesignWidth="1000"> <Grid d:DataContext="{d:DesignInstance Type=tools:InventoryViewModel, IsDesignTimeCreatable=True}"> <Grid.ColumnDefinitions> <ColumnDefinition /> <ColumnDefinition Width="5"/> <ColumnDefinition Width="2*" /> </Grid.ColumnDefinitions> <TabControl Grid.Column="0"> <TabControl.Items> <TabItem Header="Networks"> <!--<DataGrid ItemsSource="{Binding Networks}" SelectedItem="{Binding SelectedNetwork}"></DataGrid>--> <telerik:RadGridView ItemsSource="{Binding Networks}" AutoGenerateColumns="False" AlternationCount="1" GridLinesVisibility="None" CanUserDeleteRows="False" CanUserInsertRows="False" RowIndicatorVisibility="Collapsed" SelectedItem="{Binding SelectedNetwork}"> <telerik:RadGridView.Columns> <telerik:GridViewDataColumn Header="Name" UniqueName="Name" Width="100" DataMemberBinding="{Binding Name}"/> <telerik:GridViewDataColumn Header="Type" UniqueName="Type" Width="100" DataMemberBinding="{Binding IsPhysical, Converter={StaticResource NetworkTypeConverter} }"/> <telerik:GridViewDataColumn Header="Owner" UniqueName="Owner" Width="100" DataMemberBinding="{Binding ContactName}"/> </telerik:RadGridView.Columns> </telerik:RadGridView> </TabItem> </Grid></UserControl><!-- placeholder for main content area view --><ContentControl Grid.Row="1" Content="{Binding SelectedToolViewModel}" ContentTemplateSelector="{Binding Source={StaticResource SelectedToolTemplateSelector}}" /><telerikDocking:RadDocking.DocumentHost><br> <telerikDocking:RadSplitContainer x:Name="selectedItemBinder"><br> <b><telerik:RadPaneGroup DataContext="{Binding Panes}" x:Name="radPaneGroup" SelectedItem="{Binding ElementName=selectedItemBinder, Path=DataContext.SelectedPane, Mode=TwoWay}" local:RadPaneExtension.ItemsSource="{Binding}"/></b><br> </telerikDocking:RadSplitContainer><br> </telerikDocking:RadDocking.DocumentHost><Window x:Class="DockedPaneOverflow.MainWindow" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" xmlns:sample="clr-namespace:DockedPaneOverflow" Title="MainWindow" Height="350" Width="525"> <telerik:RadDocking> <telerik:RadSplitContainer InitialPosition="DockedLeft" Width="240"> <telerik:RadPaneGroup> <telerik:RadPane> <sample:UserControl1></sample:UserControl1> </telerik:RadPane> </telerik:RadPaneGroup> </telerik:RadSplitContainer> <telerik:RadDocking.DocumentHost> <telerik:RadSplitContainer> <telerik:RadPaneGroup> </telerik:RadPaneGroup> <telerik:RadPaneGroup> </telerik:RadPaneGroup> </telerik:RadSplitContainer> </telerik:RadDocking.DocumentHost> </telerik:RadDocking></Window><UserControl x:Class="DockedPaneOverflow.UserControl1" xmlns:sample="clr-namespace:DockedPaneOverflow" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"> <UserControl.Resources> <sample:RadGridViewSampleData x:Key="DataSource"/> </UserControl.Resources> <Grid> <Grid.ColumnDefinitions> <ColumnDefinition></ColumnDefinition> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition Height="15px"></RowDefinition> <RowDefinition Height="*"></RowDefinition> </Grid.RowDefinitions> <Canvas Grid.Column="0" Grid.Row="0"> <Menu> <MenuItem Header="Level 1"> <MenuItem Header="Level 1.1"/> </MenuItem> </Menu> </Canvas> <Canvas Grid.Column="0" Grid.Row="1"> <telerik:RadGridView x:Name="radGridView" Margin="8" ItemsSource="{Binding Source={StaticResource DataSource}, Path=Cars}" Width="600px" Height="394px"/> </Canvas> </Grid></UserControl>Hi,
I am still rather new to WPF in general but trying to come up to speed. I am using RadTileList in an app. I am using it for "recent items" in an application. Those items point to different modules. These modules are color coded. So when the tile renders, I want to select a particular background color of the tile, e.g. Employees = green, Crm = blue, etc.
I am using ItemsSource to a view model property
Here is the main radTileList
<telerik:RadTileList
CanUserSelect="False"
x:Name="HomeTileList"
ItemsSource="{Binding Path=RecentItems}"
GroupTemplate="{StaticResource GroupTemplate}"
Margin="5,5,0,0"
TileReorderMode="None"
ScrollViewer.HorizontalScrollBarVisibility="Auto">
....
I put in this style
<Style TargetType="telerik:Tile" >
<Setter Property="TileType" Value="Single" />
<Setter Property="Group" Value="{StaticResource tgRecent}" />
<!--<Setter Property="Background" Value="{Binding ModuleCode, Converter={StaticResource StringToTileBackgroundConverter}}"/>-->
<Setter Property="Background" Value="{StaticResource ModuleSolicitation}" />
<Setter Property="Background" Value="Black" />
<Style.Triggers>
<DataTrigger Binding="{Binding EntityId}" Value="1">
<Setter Property="Background" Value="Red" />
</DataTrigger>
</Style.Triggers>
</Style>
I have tried a value converter and a dataTrigger. In the current form, the app picks up the "black" background, but it does not seem to be checking against the EntityId field to render a Red tile.
Note: I eventually want to tied the background color based on the ModuleCode which is an enum. But I am doing EntityId for testing so that that I can have 1=1 so to speak while I figure this out.
this is "RecentItems" as the collection from the dataContext of the view.
public ObservableCollection<RecentItemViewModel> RecentItems { get; private set; }
and here is the class
public class RecentItemViewModel : ViewModelBase
{
private int _entityId;
private string _entityName;
private Enums.Module _moduleCode;
public int EntityId
{
get { return _entityId; }
set
{
if ((_entityId != value))
{
_entityId = value;
RaisePropertyChanged("EntityId");
}
}
}
public string EntityName
{
get { return _entityName; }
set
{
if ((_entityName != value))
{
_entityName = value;
RaisePropertyChanged("EntityName");
}
}
}
public Enums.Module ModuleCode
{
get { return _moduleCode; }
set
{
if ((_moduleCode != value))
{
_moduleCode = value;
RaisePropertyChanged("ModuleCode");
}
}
}
}
any ideas?
namespace Examples.TransitionControl.Common{ public static class RotatorExtensions { public static readonly DependencyProperty ItemsSourceProperty = DependencyProperty.RegisterAttached("ItemsSource", typeof(IEnumerable), typeof(RotatorExtensions), new PropertyMetadata(null, OnItemsSourceChanged)); public static readonly DependencyProperty ItemChangeDelayProperty = DependencyProperty.RegisterAttached("ItemChangeDelay", typeof(Duration), typeof(RotatorExtensions), new PropertyMetadata(new Duration(TimeSpan.FromSeconds(0.3)))); public static readonly DependencyProperty CurrentSelectedIndexProperty = DependencyProperty.RegisterAttached("CurrentSelectedIndex", typeof(int), typeof(RotatorExtensions), new PropertyMetadata(-1, OnCurrentSelectedIndexChanged)); private static readonly DependencyProperty TimerProperty = DependencyProperty.RegisterAttached("Timer", typeof(DispatcherTimer), typeof(RotatorExtensions), null); public static IEnumerable GetItemsSource(DependencyObject obj) { return (IEnumerable)obj.GetValue(ItemsSourceProperty); } public static void SetItemsSource(DependencyObject obj, IEnumerable value) { obj.SetValue(ItemsSourceProperty, value); } public static Duration GetItemChangeDelay(DependencyObject obj) { return (Duration)obj.GetValue(ItemChangeDelayProperty); } public static void SetItemChangeDelay(DependencyObject obj, Duration value) { obj.SetValue(ItemChangeDelayProperty, value); } public static int GetCurrentSelectedIndex(DependencyObject obj) { return (int)obj.GetValue(CurrentSelectedIndexProperty); } public static void SetCurrentSelectedIndex(DependencyObject obj, int value) { obj.SetValue(CurrentSelectedIndexProperty, value); } private static DispatcherTimer GetTimer(DependencyObject obj) { return (DispatcherTimer)obj.GetValue(TimerProperty); } private static void SetTimer(DependencyObject obj, DispatcherTimer value) { obj.SetValue(TimerProperty, value); } private static void OnCurrentSelectedIndexChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { UpdateCurrentlySelectedItem(d); } private static void MoveToNextElement(DependencyObject element) { IEnumerable source = GetItemsSource(element); if (source != null) { IEnumerable<object> convertedSource = source.Cast<object>(); int currentIndex = GetCurrentSelectedIndex(element); currentIndex = ++currentIndex % convertedSource.Count(); SetCurrentSelectedIndex(element, currentIndex); } } private static void OnItemsSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { FrameworkElement element = d as FrameworkElement; ItemsControl itemsControl = d as ItemsControl; IEnumerable oldValue = e.OldValue as IEnumerable; IEnumerable newValue = e.NewValue as IEnumerable; if (element != null) { if (oldValue != null) { // Detach the Ad Rotator functionality. element.Loaded -= OnElementLoaded; element.Unloaded -= OnElementUnloaded; // If there is a timer attached, stop it. DispatcherTimer timer = GetTimer(element); if (timer != null) { timer.Stop(); } } if (newValue != null) { // Attach the Ad Rotator functionality. element.Loaded += OnElementLoaded; element.Unloaded += OnElementUnloaded; // If the target is an ItemsControl and its ItemsSource is not set, set it. if (itemsControl != null && itemsControl.ItemsSource == null && itemsControl.Items.Count == 0) { itemsControl.ItemsSource = newValue; } } } } private static DependencyObject element; private static void OnElementLoaded(object sender, RoutedEventArgs args) { element = sender as DependencyObject; // Create the timer and hook-up to the events. DispatcherTimer timer = new DispatcherTimer(); timer.Interval = GetItemChangeDelay(element).TimeSpan; SetTimer(element, timer); timer.Tick += new EventHandler(timer_Tick); timer.Start(); // Make sure the currently pointed element is selected. UpdateCurrentlySelectedItem(element); } static void timer_Tick(object sender, EventArgs e) { MoveToNextElement(element); } private static void OnElementUnloaded(object sender, RoutedEventArgs args) { FrameworkElement element = sender as FrameworkElement; if (element != null) { DispatcherTimer timer = GetTimer(element); if (timer != null) { timer.Stop(); } } } private static void UpdateCurrentlySelectedItem(DependencyObject element) { ContentControl contentControl = element as ContentControl; IEnumerable source = GetItemsSource(element); // If there is no source we shouldn't do anything. if (source == null) return; // Find the actual index to be selected (if outside the boundaries of the collection) // and find the actual element to be selected. IEnumerable<object> convertedSource = source.Cast<object>(); int currentIndex = GetCurrentSelectedIndex(element); object elementToSelect = convertedSource.ElementAtOrDefault(currentIndex); // Update the cotnent of the ContentControl if attached to a ContentControl. if (contentControl != null) { contentControl.Content = elementToSelect; } } }}