Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在WPF应用程序中显示视觉效果的用户友好方式?_Wpf_User Interface - Fatal编程技术网

在WPF应用程序中显示视觉效果的用户友好方式?

在WPF应用程序中显示视觉效果的用户友好方式?,wpf,user-interface,Wpf,User Interface,寻找一种简单、优雅的方式向用户显示任何给定的视觉效果。我能想到的唯一办法就是用刷子把它刷在滚动查看器中的矩形上。这不是最好的选择 我看不出有什么方法可以做到这一点,因为视觉既没有位置也没有大小。也许可以坚持使用FrameworkElement并为其创建样式?您可以创建一个从FrameworkElement继承的包装器,该包装器将承载Visual或一个通用包装器,该包装器将承载从Visual派生的任何对象 看一看中的示例,或者,如果您想承载多个可视对象,请看一看中的(部分)示例。我(当前)的答案是

寻找一种简单、优雅的方式向用户显示任何给定的视觉效果。我能想到的唯一办法就是用刷子把它刷在滚动查看器中的矩形上。这不是最好的选择

我看不出有什么方法可以做到这一点,因为视觉既没有位置也没有大小。也许可以坚持使用FrameworkElement并为其创建样式?

您可以创建一个从
FrameworkElement
继承的包装器,该包装器将承载
Visual
或一个通用包装器,该包装器将承载从
Visual
派生的任何对象

看一看中的示例,或者,如果您想承载多个可视对象,请看一看中的(部分)示例。我(当前)的答案是将其放入XpsDocument并在DocumentViewer中显示。我想,我可以稍微简化一点,但我已经有了这样做的基础设施。虽然不是100%,但它确实有效

首先,我可以绑定到DocumentViewer.Document的行为(它是friggen POCO,呃):


只需添加一个DocumentViewer,通过行为将转换方法的结果绑定到它,就可以了。我相信这里有一条捷径…

这种低层次的联系需要什么?这似乎是一个问题,如果能从更高层次上描述你真正需要什么,我们就可以为你提供其他选择。@Aaron@Tergiver没有其他选择。我结合视觉效果来创建XPS文档。我知道它们是视觉效果,尽管它们可能是视觉效果的延伸。好吧,如果我有一个视觉效果,并把它放在另一个视觉效果中,我就不在这条线上了。我在玩DrawingVisual,可能会把它放在一个图像中,但它就像我正在进入兔子洞。。。我怎样才能获得其中一种用户体验,用户可以轻松地缩放和平移视觉效果?虽然链接指向Visual.AddVisual,但如果您查看示例,您需要将
视觉效果
放在
框架元素
中-无需将其放在
DrawingVisual
中。很抱歉造成混淆。嗯,大小和位置可以由它所在的位置决定。这就是我要找的。我能把它放进去的东西。
public sealed class XpsDocumentBinding
{
    #region Document
    /// <summary>
    /// The <see cref="DependencyProperty"/> for <see cref="Document"/>.
    /// </summary>
    public static readonly DependencyProperty DocumentProperty =
        DependencyProperty.RegisterAttached(
            "Document",
            typeof(XpsDocument), //
            typeof(XpsDocumentBinding),
            new UIPropertyMetadata(null, OnDocumentChanged));

    /// <summary>
    /// Gets the value of the <see cref="DocumentProperty">Document attached property</see> on the given <paramref name="target"/>.
    /// </summary>
    /// <param name="target">The <see cref="DependencyObject">target</see> on which the property is set.</param>
    public static XpsDocument GetDocument(DependencyObject target)
    {
        return (XpsDocument)target.GetValue(DocumentProperty);
    }

    /// <summary>
    /// Sets the <paramref name="value"/> of the <see cref="DocumentProperty">Document attached property</see> on the given <paramref name="target"/>.
    /// </summary>
    /// <param name="dependencyObject">The <see cref="DependencyObject">target</see> on which the property is to be set.</param>
    /// <param name="value">The value to set.</param>
    public static void SetDocument(DependencyObject target, XpsDocument value)
    {
        target.SetValue(DocumentProperty, value);
    }

    /// <summary>
    /// Called when Document changes.
    /// </summary>
    /// <param name="sender">The sender.</param>
    /// <param name="e">The <see cref="System.Windows.DependencyPropertyChangedEventArgs"/> instance containing the event data.</param>
    private static void OnDocumentChanged(object sender, DependencyPropertyChangedEventArgs e)
    {
        var viewer = sender as DocumentViewer;
        if (viewer == null)
            throw new InvalidOperationException(
              "This behavior is only valid on DocumetViewers.");
        var doc = e.NewValue as XpsDocument;
        if (doc == null)
            return;
        viewer.Document = doc.GetFixedDocumentSequence();
    }
    #endregion
}
var pack = PackageStore.GetPackage(_uri);
if (pack != null)
    return new XpsDocument(pack, CompressionOption.SuperFast, _uri.AbsoluteUri);

MemoryStream ms = new MemoryStream(2048);
Package p = Package.Open(ms, FileMode.Create, FileAccess.ReadWrite);
PackageStore.AddPackage(_uri, p);
XpsDocument doc = new XpsDocument(p, CompressionOption.SuperFast, _uri.AbsoluteUri);

var writer = XpsDocument.CreateXpsDocumentWriter(doc);
var collator = writer.CreateVisualsCollator();
// write the visuals using our collator
collator.BeginBatchWrite();
collator.Write(Visual);
collator.EndBatchWrite();
p.Flush();
return doc;