UWP 动态磁贴未更新
UWP Live Tile not updating
当我尝试更新我的 UWP 主要和/或次要磁贴时,什么也不会发生。
如果我从 Visual Studio 2017 年开始我的 UWP 应用程序,更新功能可以正常工作并更新磁贴。
但是,如果我从 VS 2017 制作一个 Windows Store 应用程序,更新功能将不再起作用。
这是我当前的更新函数:
using System;
using System.Diagnostics;
using Windows.Data.Xml.Dom;
using Windows.UI.Notifications;
using Windows.UI.Xaml.Controls;
namespace UpdateTile
{
public sealed class TileUpdate
{
// Function which is call by every background task to update the app tile
// and each app secondary tile
// The tile ID could be empty for update the primary tile
public static void ScheduleUpdate(String data, String tileID)
{
#region variables
TileUpdater tileUpdater = null;
#endregion
// Check the tile ID
if (tileID == "")
{
// If tile ID is empty then create a tile updater for the app tile
tileUpdater = TileUpdateManager.CreateTileUpdaterForApplication();
}
else
{
tileUpdater = TileUpdateManager.CreateTileUpdaterForSecondaryTile(tileID);
}
tileUpdater.EnableNotificationQueue(true);
tileUpdater.Clear();
tileUpdater.Update(new TileNotification(new TileXML().WriteXml(data)));
}
}
}
}
这就是我实际为图块创建 XML 的方式:
using System;
using System.Diagnostics;
using SystemInformation;
using Windows.Data.Xml.Dom;
using Windows.UI.Notifications;
using Microsoft.Toolkit.Uwp.Notifications;
namespace UpdateTile
{
public sealed class TileXML
{
// Function to create a xml document for tiles
// returns a xml document
public XmlDocument WriteXml(String data)
{
#region variables
String[] result = { "" }; ;
SystemInfo sysinfo = new SystemInfo();
TileContent content = null;
String textCaption = "";
String textCaptionSubTle1 = "";
String textCaptionSubTle2 = "";
String textCaptionSubTle3 = "";
#endregion
Debug.WriteLine("Create xml document for tile");
if (String.IsNullOrEmpty(data))
{
// Set xml text for initial text file data
textCaption = "No data available";
}
else
{
// Split text file data by carriage return and new line
result = data.Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
// check the result length to create an xml document text
if (result.Length == 1)
{
// Set xml text if no data file exists
textCaption = "No data available";
}
else
{
// Set xml text if data file is present
textCaption = sysinfo.Hostname;
textCaptionSubTle1 = result[3].Replace("Enterprise", "") + " v" + result[4];
textCaptionSubTle2 = "IP: " + sysinfo.IP_Address;
textCaptionSubTle3 = "Hotline: " + result[1];
}
}
// Create an adaptive tile content
content = new TileContent()
{
Visual = new TileVisual()
{
TileWide = new TileBinding()
{
Content = new TileBindingContentAdaptive()
{
BackgroundImage = new TileBackgroundImage()
{
Source = "Assets/Backgroung.png",
HintOverlay = 60
},
Children =
{
new AdaptiveText()
{
Text = textCaption,
HintStyle = AdaptiveTextStyle.Caption
},
new AdaptiveText()
{
Text = textCaptionSubTle1,
HintStyle = AdaptiveTextStyle.CaptionSubtle
},
new AdaptiveText()
{
Text = textCaptionSubTle2,
HintStyle = AdaptiveTextStyle.CaptionSubtle
},
new AdaptiveText()
{
Text = textCaptionSubTle3,
HintStyle = AdaptiveTextStyle.CaptionSubtle
}
}
}
}
}
};
// return the xml domument from adaptive tile content
return content.GetXml();
}
}
}
我也尝试过使用 RAW XML 来更新图块,但没有任何效果。有谁知道为什么磁贴更新适用于 VS 2017,但不适用于 Windows 商店应用程序?
发布者证书已作为根证书导入。
关于我的系统的信息:
OS: Windows 10 v1703 --> 版本: 10.0.15063.540
问题已自行解决
当我为动态磁贴创建 XML 时,我设置了背景图片:
BackgroundImage = new TileBackgroundImage()
{
Source = "Assets/Backgroung.png",
HintOverlay = 60
},
当我将其注释掉并制作一个新的 Windows 商店应用程序时,实时更新将再次运行。
可能图片尺寸不对
当我尝试更新我的 UWP 主要和/或次要磁贴时,什么也不会发生。
如果我从 Visual Studio 2017 年开始我的 UWP 应用程序,更新功能可以正常工作并更新磁贴。 但是,如果我从 VS 2017 制作一个 Windows Store 应用程序,更新功能将不再起作用。
这是我当前的更新函数:
using System;
using System.Diagnostics;
using Windows.Data.Xml.Dom;
using Windows.UI.Notifications;
using Windows.UI.Xaml.Controls;
namespace UpdateTile
{
public sealed class TileUpdate
{
// Function which is call by every background task to update the app tile
// and each app secondary tile
// The tile ID could be empty for update the primary tile
public static void ScheduleUpdate(String data, String tileID)
{
#region variables
TileUpdater tileUpdater = null;
#endregion
// Check the tile ID
if (tileID == "")
{
// If tile ID is empty then create a tile updater for the app tile
tileUpdater = TileUpdateManager.CreateTileUpdaterForApplication();
}
else
{
tileUpdater = TileUpdateManager.CreateTileUpdaterForSecondaryTile(tileID);
}
tileUpdater.EnableNotificationQueue(true);
tileUpdater.Clear();
tileUpdater.Update(new TileNotification(new TileXML().WriteXml(data)));
}
}
}
}
这就是我实际为图块创建 XML 的方式:
using System;
using System.Diagnostics;
using SystemInformation;
using Windows.Data.Xml.Dom;
using Windows.UI.Notifications;
using Microsoft.Toolkit.Uwp.Notifications;
namespace UpdateTile
{
public sealed class TileXML
{
// Function to create a xml document for tiles
// returns a xml document
public XmlDocument WriteXml(String data)
{
#region variables
String[] result = { "" }; ;
SystemInfo sysinfo = new SystemInfo();
TileContent content = null;
String textCaption = "";
String textCaptionSubTle1 = "";
String textCaptionSubTle2 = "";
String textCaptionSubTle3 = "";
#endregion
Debug.WriteLine("Create xml document for tile");
if (String.IsNullOrEmpty(data))
{
// Set xml text for initial text file data
textCaption = "No data available";
}
else
{
// Split text file data by carriage return and new line
result = data.Split(new string[] { "\n", "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
// check the result length to create an xml document text
if (result.Length == 1)
{
// Set xml text if no data file exists
textCaption = "No data available";
}
else
{
// Set xml text if data file is present
textCaption = sysinfo.Hostname;
textCaptionSubTle1 = result[3].Replace("Enterprise", "") + " v" + result[4];
textCaptionSubTle2 = "IP: " + sysinfo.IP_Address;
textCaptionSubTle3 = "Hotline: " + result[1];
}
}
// Create an adaptive tile content
content = new TileContent()
{
Visual = new TileVisual()
{
TileWide = new TileBinding()
{
Content = new TileBindingContentAdaptive()
{
BackgroundImage = new TileBackgroundImage()
{
Source = "Assets/Backgroung.png",
HintOverlay = 60
},
Children =
{
new AdaptiveText()
{
Text = textCaption,
HintStyle = AdaptiveTextStyle.Caption
},
new AdaptiveText()
{
Text = textCaptionSubTle1,
HintStyle = AdaptiveTextStyle.CaptionSubtle
},
new AdaptiveText()
{
Text = textCaptionSubTle2,
HintStyle = AdaptiveTextStyle.CaptionSubtle
},
new AdaptiveText()
{
Text = textCaptionSubTle3,
HintStyle = AdaptiveTextStyle.CaptionSubtle
}
}
}
}
}
};
// return the xml domument from adaptive tile content
return content.GetXml();
}
}
}
我也尝试过使用 RAW XML 来更新图块,但没有任何效果。有谁知道为什么磁贴更新适用于 VS 2017,但不适用于 Windows 商店应用程序?
发布者证书已作为根证书导入。
关于我的系统的信息: OS: Windows 10 v1703 --> 版本: 10.0.15063.540
问题已自行解决
当我为动态磁贴创建 XML 时,我设置了背景图片:
BackgroundImage = new TileBackgroundImage()
{
Source = "Assets/Backgroung.png",
HintOverlay = 60
},
当我将其注释掉并制作一个新的 Windows 商店应用程序时,实时更新将再次运行。
可能图片尺寸不对