The Items in FlowItemsControl2D not showing up

Apr 18, 2012 at 8:09 AM

Hi, 

   First of all I must congratulate you for the nice control that you created. I am trying to use your control in one of my project. I did as per my understanding all the things that is there in your sample project. But unfortunately the items in the control is not showing up. Below is my xaml code.

 

<UserControl x:Class="XCloud.DTE.Views.GalleryViews.ServiceGalleryView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
    xmlns:flow="clr-namespace:SStuff.FlowControls;assembly=SStuff.FlowControls"
    xmlns:u="clr-namespace:XCloud.DTE.Utils"
    xmlns:tk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit"         
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400" u:AttachedPropeties.Title="Service Gallery">
    <UserControl.Resources>

        <Style TargetType="flow:FlowItem3D" x:Key="empty3D">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="flow:FlowItem3D">
                        <ContentPresenter />
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style TargetType="flow:FlowItem2D" x:Key="empty2D">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="flow:FlowItem2D">
                        <ContentPresenter />
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <DataTemplate x:Key="itemTemplate">
            <flow:InFlowContentControl Content="{Binding ColorName}" Background="{Binding Brush}" HeadingBackground="{Binding HeaderBrush}" Width="150" Height="150" />
        </DataTemplate>

    </UserControl.Resources>

    <Grid Background="#60FFFFFF">
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="0.3*"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <flow:FlowItemsControl2D ItemsSource="{Binding Items}" ItemTemplate="{StaticResource itemTemplate}" ItemContainerStyle="{StaticResource empty2D}" />
    </Grid>
</UserControl>

And below is my code for the view model

using XCloud.Client.SilverlightFramework.ViewModel;
using XCloud.Model;
using System.Windows.Media;
using System.Collections.Generic;
using System.Linq;

namespace XCloud.DTE.ViewModels
{
    [ExportAsViewModel(typeof(ServiceGalleryViewModel))]
    public class ServiceGalleryViewModel : BaseViewModel
    {
        protected override void ActivateView(string viewName, System.Collections.Generic.IDictionary<string, object> viewParameters)
        {
            var templates = new ServiceTemplateList();
            templates.Execute((s,f) =>
                {
                    this.Templates = templates;
                });

        }

        private ServiceTemplateList _templates;

        public ServiceTemplateList Templates
        {
            get { return this._templates; }
            set 
            { 
                this._templates = value;
                RaisePropertyChanged("Templates");
            }
        }


         public class Item
        {
            public string ColorName { get; set; }
            public Brush Brush { get; set; }
            public Brush HeaderBrush { get; set; }
        }

        private readonly List<Item> _items = new List<Item>();
        public List<Item> Items { get { return _items; } }

        public ServiceGalleryViewModel()
        {
            foreach (var property in typeof(Colors).GetProperties(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public).Where(p => p.PropertyType == typeof(Color) && p.Name != "Transparent"))
            {
                var name = property.Name;
                var color = (Color) property.GetValue(null, null);
                var bg = new SolidColorBrush(color);
                var headerBrush = new LinearGradientBrush(new GradientStopCollection
                {
                    new GradientStop{Offset=0, Color = Color.FromArgb(255,(byte) (color.R *0.5),(byte) (color.G *0.5),(byte) (color.B *0.5))},
                    new GradientStop{Offset=1, Color = Color.FromArgb(20,(byte) (color.R *0.5),(byte) (color.G *0.5),(byte) (color.B *0.5))}
                }, 0);

                _items.Add(new Item { Brush = bg, ColorName = name, HeaderBrush = headerBrush });

            }

        }
       
    }
}

Now just to let you know here the framework takes care of putting the viewmodel to the view. That is the framework first. Creates 
the view model and then assign it to the datacontext of the view and then display the view. Please do let me know if it helps you to 
understand my problem and if you can help me fix it. 

Regards
Tiklu

Apr 18, 2012 at 8:53 AM

Ok here is some more info I though I should add which will help you find the issue. I did found that it is properly setting 14 items in the control and data context is getting properly assigned. So logically it is getting the data source and itemssource. But nothing is showing up.. :(