Binding Properties not updating (1 Viewer)

sccrgoalie1

Portal Pro
September 12, 2013
109
165
38
Home Country
United States of America United States of America
I wasn't able to make HeaderedItemsControl work properly, but have solved my issue. I suspect the problem with the HeaderedItemsControl is getting a proper Style built. I'm going to post my working code below in case others come looking and have a similar problem with binding. Specfically what this style lets you do is place items on the screen using X, Y coordinates which is what I need for my plugin.

XAML
Code:
<Screen xmlns="www.team-mediaportal.com/2008/mpf/directx"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:collections="clr-namespace:MediaPortal.UI.Presentation.DataObjects;assembly=MediaPortal.UI"
        Context="{Model Id=C6B0FA5A-288E-405A-A5D5-AA66CC0AA327}">
    <Screen.Resources>
        <DataTemplate x:Key="ItemDataTemplate" DataType="{x:Type collections:ListItem}">
            <Canvas>
                <Grid Canvas.Left="{Binding LeftProperty}" Canvas.Top="{Binding TopProperty}">
                    <Border x:Name="PictureBorder" MaxWidth="{Binding Path=PictureWidthProperty}"
                            MaxHeight="{Binding Path=PictureHeightProperty}"
                            HorizontalAlignment="Left" VerticalAlignment="Top" >
                        <Border.Background>
                            <ImageBrush ImageSource="{Binding Path=BorderImageProperty}" Tile="Tile"/>
                        </Border.Background>
                        <Image Source ="{Binding Path=PictureImageProperty}" Stretch="Uniform" Margin ="{Binding Path=PictureBorderMarginsProperty}"/>
                    </Border>
                    <Label x:Name="PictureLabel" Content="{Binding Path=PictureDateProperty}"
                          HorizontalAlignment="Center" VerticalAlignment="Bottom"
                          Color="{Binding Path=PictureDateColorProperty}" FontSize="8"/>
                </Grid>
            </Canvas>
        </DataTemplate>
        <Style x:Key="ListViewStyle" BasedOn="{ThemeResource DefaultListViewStyle}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ListView}">
                            <ItemsPresenter VerticalAlignment="Stretch" HorizontalAlignment="Stretch"/> 
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="ItemTemplate" Value="{ThemeResource ItemDataTemplate}"/>
            <Setter Property="ItemsPanel">
                <Setter.Value>
                    <ItemsPanelTemplate>
                        <Grid x:Name="ListItemsHost" IsItemsHost="True"/>
                    </ItemsPanelTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Screen.Resources>     
    <Canvas>
        <Canvas.Background>
            <ImageBrush ImageSource="{Binding Path=SlideshowBackgroundProperty}" Stretch="Fill"/>
        </Canvas.Background>
        <ListView Style="{ThemeResource ListViewStyle}" ItemsSource="{Binding Path=PictureList}"/>       
    </Canvas>
</Screen>

BindingPicture class
Code:
using MediaPortal.Common.General;
using MediaPortal.UI.Presentation.DataObjects;
using System;
using System.Linq;
using System.Text;

namespace MPPhotoSlideshow
{
  public class BindingPicture : ListItem
  {
    protected readonly AbstractProperty _left = new WProperty(typeof(int), 0);
    protected readonly AbstractProperty _top = new WProperty(typeof(int), 0);
    protected readonly AbstractProperty _pictureImage = new WProperty(typeof(string), string.Empty);
    protected readonly AbstractProperty _pictureWidth = new WProperty(typeof(int), 0);
    protected readonly AbstractProperty _pictureHeight = new WProperty(typeof(int), 0);
    protected readonly AbstractProperty _borderImage = new WProperty(typeof(string), string.Empty);
    protected readonly AbstractProperty _pictureBorderMargins = new WProperty(typeof(string), string.Empty);
    protected readonly AbstractProperty _pictureDate = new WProperty(typeof(string), string.Empty);
    protected readonly AbstractProperty _pictureDateColor = new WProperty(typeof(string), string.Empty);

    // Public properties
    public int Left
    {
      get { return (int)_left.GetValue(); }
      set { _left.SetValue(value); }
    }
    public int Top
    {
      get { return (int)_top.GetValue(); }
      set { _top.SetValue(value); }
    }
    public int PictureWidth
    {
      get { return (int)_pictureWidth.GetValue(); }
      set { _pictureWidth.SetValue(value); }
    }
    public int PictureHeight
    {
      get { return (int)_pictureHeight.GetValue(); }
      set { _pictureHeight.SetValue(value); }
    }
    public string BorderImage
    {
      get { return (string)_borderImage.GetValue(); }
      set { _borderImage.SetValue(value); }
    }
    public string PictureBorderMargins
    {
      get { return (string)_pictureBorderMargins.GetValue(); }
      set { _pictureBorderMargins.SetValue(value); }
    }
    public string PictureDate
    {
      get { return (string)_pictureDate.GetValue(); }
      set { _pictureDate.SetValue(value); }
    }
    public string PictureDateColor
    {
      get { return (string)_pictureDateColor.GetValue(); }
      set { _pictureDateColor.SetValue(value); }
    }
    public string PictureImage
    {
      get { return (string)_pictureImage.GetValue(); }
      set { _pictureImage.SetValue(value); }
    }
    public AbstractProperty PictureWidthProperty
    {
      get { return _pictureWidth; }
    }
    public AbstractProperty PictureHeightProperty
    {
      get { return _pictureHeight; }
    }
    public AbstractProperty BorderImageProperty
    {
      get { return _borderImage; }
    }
    public AbstractProperty PictureBorderMarginsProperty
    {
      get { return _pictureBorderMargins; }
    }
    public AbstractProperty PictureDateProperty
    {
      get { return _pictureDate; }
    }
    public AbstractProperty PictureDateColorProperty
    {
      get { return _pictureDateColor; }
    }
    public AbstractProperty PictureImageProperty
    {
      get { return _pictureImage; }
    }

    public AbstractProperty TopProperty
    {
      get { return _top; }
    }

    public AbstractProperty LeftProperty
    {
      get { return _left; }
    }
  }
}

Model
Code:
protected readonly ItemsList _pictureList = new ItemsList(); 
  /// <summary>
    /// Exposes the picture list to the skin
    /// </summary>
    public ItemsList PictureList
    {
      get { return _pictureList; }
    }
private void LoadPage()
{
PictureList.Clear();
        PhotoTemplate template = _photoTemplates[_templateRnd.Next(_photoTemplates.Count)];
        for (int i = 0; i < template.Photos.Count; i++)
        {
          if (template.Photos[i].Enabled)
          {
            Picture pictureFileName = GetPicture(template, i);
            Log.Debug(pictureFileName.FilePath);
            Size ImageMargin = ScaleToScreen(template.Photos[i].Image.posY, template.Photos[i].Image.posX);
            Size ImageSize = ScaleToScreen(template.Photos[i].Image.Height, template.Photos[i].Image.Width);
            PictureList.Add(new BindingPicture()
            {
              BorderImage = template.Photos[i].Image.BorderPath,
              PictureBorderMargins = String.Format("{0},{1},{2},{3}", template.Photos[i].Image.BorderLeft, template.Photos[i].Image.BorderTop, template.Photos[i].Image.BorderRight, template.Photos[i].Image.BorderBottom),
              Left = Convert.ToInt32(ImageMargin.Width),
              Top = Convert.ToInt32(ImageMargin.Height),
              PictureDate = pictureFileName.DateTaken.ToString("d"),
              PictureDateColor = template.Photos[i].Label.TextColor,
              PictureHeight = Convert.ToInt32(ImageSize.Height),
              PictureWidth = Convert.ToInt32(ImageSize.Width),
              PictureImage = pictureFileName.FilePath,
            });
          }
        }
        Log.Debug("Firing picture list changed with count of {0}", PictureList.Count);
        PictureList.FireChange();    
}
 

Users who are viewing this thread

Top Bottom