- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在 Silverlight 中创建一个 Path
,并在鼠标事件中向其添加元素。但是,尽管元素在内存中,但屏幕不会更新,直到其他原因导致屏幕重绘发生。
这是相关代码 - 我正在响应鼠标事件,并且我保留了我正在编辑的路径的类成员。
Path path = null;
private void LayoutRoot_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
Point thisPoint = e.GetPosition(LayoutRoot);
if (path == null)
{
CreateNewPath(thisPoint);
path.LayoutUpdated += new EventHandler(path_LayoutUpdated);
}
else
{
path.AddLineElement(thisPoint);
}
}
private void CreateNewPath(Point startPoint)
{
path = new Path();
PathGeometry geometry = new PathGeometry();
path.Data = geometry;
PathFigureCollection figures = new PathFigureCollection();
geometry.Figures = figures;
PathFigure figure = new PathFigure();
figures.Add(figure);
figure.StartPoint = startPoint;
figure.Segments = new PathSegmentCollection();
path.Stroke = new SolidColorBrush(Colors.Red);
path.StrokeThickness = 2;
path.Stretch = Stretch.None;
LayoutRoot.Children.Add(path);
}
AddLineElement
是路径类的扩展方法,只是为了简化:
public static class PathHelper
{
public static void AddLineElement(this Path thePath, Point newPoint)
{
PathGeometry geometry = thePath.Data as PathGeometry;
geometry.Figures[0].Segments.Add(new LineSegment { Point = newPoint });
}
}
这是重现问题所需的最低限度。如果您在完整的 WPF 应用程序中运行此代码,它会按预期运行。单击鼠标添加立即出现的行元素。但是,在 Silverlight 中,情况就不同了。这些点击似乎什么也没做,即使单步执行代码显示数据正在添加。但是,如果您点击几次,然后调整浏览器的大小,例如,路径元素就会出现。如果你碰巧在页面上也有一个按钮,将鼠标移到上面,路径就会出现。
我已经尝试了所有明显的事情,比如在 Path
(和父网格)上调用 InvalidateMeasure
和 InvalidateArrange
到 no有用。
我唯一的解决方法是更改路径上的一个属性,然后再将其改回来,这似乎足以让渲染引擎绘制新的路径元素。我使用 不透明度
。您必须将其设置为不同的值,否则(我认为)PropertyChanged
事件不会触发。不过,这是一种拼凑。
有没有人用这种方式玩过路径?我想如果我同时将其他图形元素放在屏幕上,这不会是一个问题,所以它可能不会影响很多人,但最好知道是否有更正确的方法来做到这一点.
最佳答案
我需要一些非常相似的东西,但使用了新的 Silverlight VE map 控件。您上面的代码工作正常,没有任何摆弄其他属性来“强制重绘”。此处代码供您引用:
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using Microsoft.VirtualEarth.MapControl;
namespace MapInfo
{
public partial class Page : UserControl
{
/// <summary>
/// Sample drawing a polyline on a Virtual Earth map
/// </summary>
public Page()
{
InitializeComponent();
VEMap.MouseLeftButtonUp += new MouseButtonEventHandler(VEMap_MouseLeftButtonDown);
VEMap.MouseLeave += new MouseEventHandler(VEMap_MouseLeave);
}
MapPolyline polyline = null;
/// <summary>
/// Ends drawing the current polyline
/// </summary>
void VEMap_MouseLeave(object sender, MouseEventArgs e)
{
polyline = null;
}
/// <summary>
/// Start or add-to a polyline
/// </summary>
private void VEMap_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
Map m = (Map)sender;
Location l = m.ViewportPointToLocation(e.GetPosition(m));
if (polyline == null)
{
CreateNewPolyline(l);
}
else
{
polyline.Locations.Add(l);
}
}
/// <summary>
/// Create a new MapPolyline
/// </summary>
/// <param name="startPoint">starting Location</param>
private void CreateNewPolyline(Location startPoint)
{
polyline = new MapPolyline();
polyline.Stroke = new SolidColorBrush(Colors.Red);
polyline.StrokeThickness = 2;
var lc = new LocationCollection();
lc.Add(startPoint);
polyline.Locations = lc;
VEMap.Children.Add(polyline);
}
}
}
对您眼前的情况没有帮助,但表明其他 Silverlight 的东西可以按您的预期工作。可能会帮助其他人,我希望...
关于c# - 当我以编程方式将段添加到 Silverlight 2 中的路径时,为什么我的路径不显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/249866/
我正在尝试从 F# 编译代码以在 Silverlight 中使用。我编译: --noframework --cliroot "C:\program Files\Microsoft Silverligh
我正在为 Silverlight 安装一个编程环境并试图理顺需要安装的内容,感谢反馈: 在 http://silverlight.net/GetStarted ,第一点允许您安装“ Silverlig
Silverlight RIA 值得学习还是我应该坚持普通的 Silverlight? 背景: 我在 WPF 中做了几个小应用程序 我有 12 年的 VB6/WinForms 模型商业应用经验 我希望
我已经熟悉 Silverlight 编程,但没有任何 GIS 经验。 我作为 Silverlight 开发人员的角色只是显示现有的 GIS 数据。 如果你们有任何经验arcGIS silverligh
我需要在我的 Silverlight 应用程序中创建滚动选取框。选取框需要从右向左滚动。当它完成滚动时,它需要自动重新启动 诀窍是,我需要使用 ItemsControl,因为项目将在滚动时添加到列表中
Silverlight 导航模板在浏览器外运行时是否有效? 最佳答案 当然可以。 并且您可以使用 NavigationServices 函数来创建自定义的“后退”或“前进”按钮 很好的例子:Link
用户通过导航到给定的 URL 在他们的浏览器中启动 Silverlight 应用程序。 然后用户打开另一个浏览器并通过导航到相同的 URL 启动相同的 Silverlight 应用程序。 应用程序的第
Silverlight 4 程序集二进制文件是否与 Silverlight 5 兼容。SL4 程序集是否“在 SL5 运行时中运行”?如果兼容,是否100%兼容。您应该能够在您的 SL5 项目中使用第
很难说出这里问的是什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或言辞激烈,无法以目前的形式合理回答。如需帮助澄清此问题以便可以重新打开,visit the help center . 9年前关闭
我正在寻找是否可以在可以在 application.resources 中设置然后在整个应用程序中使用的 Silverlight 控件中使用应用程序范围的字体。他们不需要指定有关字体的其他内容,例如粗
我正在使用Silverlight4。我想用一个可用字体列表填充组合框。我搜索过很多东西,找不到解决方法。似乎有很多死胡同。五月份曾提出过类似的问题,但没有合适的答案。 当然不是不可能吗? 最佳答案 如
我正在为 Silverlight 很好地实现弱事件模式以避免内存泄漏。 似乎有一些实现,但代码并非微不足道,很难知道哪个是正确的。我找不到微软的任何官方推荐。 如果可能的话,我追求简单的语法。 干杯。
Silverlight 应用程序是在您每次访问该站点时都会下载,还是会检查版本/大小信息并仅下载较新版本的文件? 最佳答案 Silverlight 2 在这方面没有什么特别的,我读过的最简洁的解释来自
我正在尝试在 silverlight 中使用样式触发器,如下所示:
我想尝试制作一个包含多个 Silverlight 画廊中的图片的 asp 网站。我想这样做的原因是我想要这样的东西: Text describing some places. Gallery with
WPF 3.5 有 PresentationTraceSources用于诊断和WPFPerf用于性能和数据绑定(bind)诊断。 Silverlight 是否有等效的工具/库? 最佳答案 尽管我已将
我有一个表示有向图的数据结构,我正在寻找一个好的 Silverlight 可视化,以允许我从一个节点导航到另一个节点,最好有一些漂亮的动画。 有没有人知道这种显示的任何好的 UI 控件或框架?甚至来自
我可以将byte []转换为图像: byte[] myByteArray = ...; // ByteArray to be converted MemoryStream ms = new Memo
我有多个Silverlight项目,希望使用相同的样式,配色方案和一些模板化对象。 我该如何完成? 最佳答案 一种实现方法是创建一个新的silverlight类库,该库将是您共享的主题/样式程序集,其
我正在尝试使用 SLLAUNCHER.EXE 启动已安装的 SL Out-of-Browser App。运行以下命令后,桌面上的 MyApp 启动图标就消失了。如果我在没有覆盖开关的情况下尝试它,则不
我是一名优秀的程序员,十分优秀!