2010-12-03 3 views
1

주어진 Visual을 사용자에게 표시하는 간단하고 우아한 방법을 찾고 있습니다. 머리에서 벗어날 수있는 유일한 방법은 붓으로 그것을 치고 ScrollViewer에있는 사각형에 페인트하는 것입니다. 꼭 최선의 선택은 아닙니다.WPF 응용 프로그램에서 Visual을 표시하기위한 사용자 친화적 인 방법은 무엇입니까?

+0

저급 넥타이가 필요한 이유는 무엇입니까? –

+1

이것은 우리가 당신에게 대안을 줄 수 있도록 당신이 정말로 필요로하는 것에 대한 더 높은 수준의 설명으로부터 이익을 얻는 그러한 질문 중 하나와 같습니다. – Tergiver

+0

@Aaron @Tergiver 대안이 존재하지 않습니다. 나는 비주얼을 결합하여 XpsDocuments를 생성합니다. 비주얼에서 확장 한 것이라 할지라도 나는 그것들을 비주얼이라고 알고 있습니다. – Will

답변

0

내 (현재) 대답에 (부분) 예를 살펴하려는 경우

Visual.AddVisual의 예를 살펴 또는 XpsDocument를 만들고 DocumentViewer에 표시합니다. 나는 다소 복잡하지는 않지만 이미 그렇게 할 수있는 기반 시설을 갖추고 있습니다. 100 %는 아니지만 작동합니다.

첫째, 내가 DocumentViewer.Document에 결합 할 수 있도록 행동 (자사의 friggen POCO, urgh) :

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 
} 

그럼 내 모델에서 내가 XpsDocument

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; 
나의 시각을 노출

DocumentViewer를 추가하고 비헤이비어를 통해 변환 메소드의 결과를 바인드하면됩니다. 나는 어딘가에 여기에 지름길이있을 것이라고 확신한다 ...

1

Visual에는 위치 나 크기가 없으므로 어떻게 할 수 있는지 알 수 없습니다. 아마도 FrameworkElement에 집착하여 스타일을 만들겠습니까?

+0

음, 크기와 위치는 그것이 무엇인지에 따라 결정될 수 있습니다. 내가 찾고있는 것은 무엇입니까. 내가 그것을 넣을 수있는 것. – Will

2

Visual 또는 Visual에서 파생 된 모든 개체를 호스팅하는 일반 래퍼를 호스팅하는 FrameworkElement을 상속하는 래퍼를 만들 수 있습니다. 당신은 하나 이상의 시각적 호스트에 때려하는 것입니다 Using DrawingVisual Objects

+0

글쎄, 내가 시각적으로 다른 시각 자료에 넣으면 나는 훨씬 더 멀리 떨어지지는 않는다. DrawingVisual에서 놀고 있었고 이미지에 넣을 수도 있었지만 토끼 구멍을 내려가는 것과 같았습니다 ... 어떻게하면 사용자가 쉽게 확대/축소하고 회전 할 수있는 사용자 경험을 얻을 수 있습니까? 비주얼? – Will

+0

링크가 Visual.AddVisual을 가리키고 있지만 예제를 보면'FrameworkElement'에서'Visual'을 호스트해야합니다. - DrawingVisual 안에 넣을 필요가 없습니다. 혼란에 대해 죄송합니다. – Samuel

관련 문제