- September 12, 2013
- 109
- 165
- 38
- Home Country
- United States of America
Hello,
I'm slowly learning the new MP2 development and I'm having an issue with Binding that I can figure out. I know my model is bound correctly because when I set the property on first load it works just fine. The problem is when I try to update that property later nothing happens. Here's the relevant code:
XAML
CS
Any idea why this isn't updating. The LoadPage() method is called every 10 seconds via a timer tick event.
I'm slowly learning the new MP2 development and I'm having an issue with Binding that I can figure out. I know my model is bound correctly because when I set the property on first load it works just fine. The problem is when I try to update that property later nothing happens. Here's the relevant code:
XAML
XML:
<Grid x:Name="Picture1Grid" Margin="{Binding Path=Picture1GridMargin}">
<Grid.RenderTransform>
<TransformGroup>
<RotateTransform CenterX="100" CenterY="75" Angle="0" />
<ScaleTransform ScaleX="1" ScaleY="1"/>
</TransformGroup>
</Grid.RenderTransform>
<Border x:Name="Picture1Border" BorderBrush="White"
BorderThickness="10" MaxWidth="{Binding Path=Picture1Width}"
MaxHeight="{Binding Path=Picture1Height}"
HorizontalAlignment="Left" VerticalAlignment="Top" >
<Image Source ="{Binding Path=Picture1}" Stretch="Uniform"/>
</Border>
<Label x:Name="Picture1Label" Content="{Binding Path=Picture1Date}"
HorizontalAlignment="Center" VerticalAlignment="Bottom"
Color="{Binding Path=Picture1DateColor}" FontSize="8"/>
</Grid>
CS
C#:
protected readonly AbstractProperty _picture1Property;
protected readonly AbstractProperty _picture1GridMargin;
protected readonly AbstractProperty _picture1Date;
protected readonly AbstractProperty _picture1DateColor;
protected readonly AbstractProperty _picture1Width;
protected readonly AbstractProperty _picture1Height;
public MPPhotoSlideshowModel()
{
try
{
// In models, properties will always be WProperty instances. When using SProperties for screen databinding,
// the system might run into memory leaks.
log = new Log(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + @"\Team MediaPortal\MP2-Client\Log", "MPPhotoSlideshow", "log", LogType.Debug);
_helloStringProperty = new WProperty(typeof(string), HELLOWORLD_RESOURCE);
_picture1Property = new WProperty(typeof(object), null);
_picture1Date = new WProperty(typeof(string), null);
_picture1GridMargin = new WProperty(typeof(object), null);
_picture1DateColor = new WProperty(typeof(object), null);
_picture1Width = new WProperty(typeof(object), null);
_picture1Height = new WProperty(typeof(object), null);
LoadSettings();
LoadPage();
}
catch (Exception ex)
{
if (log != null)
{
log.writeLog(ex.ToString(), LogInfoType.Error);
}
}
}
public string Picture1Date
{
get { return (string)_picture1Date.GetValue(); }
set { _picture1Date.SetValue(value); }
}
public object Picture1
{
get { return (object)_picture1Property.GetValue(); }
set { _picture1Property.SetValue(value); }
}
public object Picture1GridMargin
{
get { return (object)_picture1GridMargin.GetValue(); }
set { _picture1GridMargin.SetValue(value); }
}
public object Picture1DateColor
{
get { return (object)_picture1DateColor.GetValue(); }
set { _picture1DateColor.SetValue(value); }
}
public object Picture1Height
{
get { return (object)_picture1Height.GetValue(); }
set { _picture1Height.SetValue(value); }
}
public object Picture1Width
{
get { return (object)_picture1Width.GetValue(); }
set { _picture1Width.SetValue(value); }
}
private void LoadPage()
{
try
{
PhotoTemplate template = _photoTemplates[_templateRnd.Next(_photoTemplates.Count)];
if (template.Photos[0].Enabled)
{
Picture picture1FileName;
if (template.Photos[0].Image.Height > template.Photos[0].Image.Width)
{
picture1FileName = _verticalPictures[_verticalRnd.Next(_verticalPictures.Count)];
}
else
{
picture1FileName = _horizontalPictures[_horizontalRnd.Next(_horizontalPictures.Count)];
}
//log.writeLog(String.Format("MPSlideshow.LoadPage() - Setting new file name {0}",picture1FileName.FilePath), LogInfoType.Debug);
Picture1 = picture1FileName.FilePath;
Picture1GridMargin = String.Format("{0},{1},{2},{3}", template.Photos[0].Image.posX, template.Photos[0].Image.posY, 0, 0);
Picture1Date = picture1FileName.DateTaken.ToString("d");
Picture1DateColor = template.Photos[0].Label.TextColor;
Picture1Width = template.Photos[0].Image.Width;
Picture1Height = template.Photos[0].Image.Height;
}
}
catch (Exception ex)
{
log.writeLog(ex.ToString(), LogInfoType.Error);
}
}
Any idea why this isn't updating. The LoadPage() method is called every 10 seconds via a timer tick event.
Last edited by a moderator: