任意のVisualをユーザーに表示する、シンプルで洗練された方法を探しています。私が頭を離して考えることができる唯一の方法は、ブラシでそれを叩き、それをScrollViewerのRectangleにペイントすることです。正確には最良の選択肢ではありません。WPFアプリケーションでビジュアルを表示するのに便利な方法は?
1
A
答えて
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
をホストするFrameworkElement
か、Visual
から派生するオブジェクトをホストする汎用ラッパーを継承するラッパーを作成できます。あなたは、複数の視覚的なホストでそれを平手打ちすることですUsing DrawingVisual Objects
関連する問題
- 1. 便利な方法()
- 2. 便利な方法は
- 3. すぐに検査するのに便利なインライン表示方法
- 4. 便利な方法でスプライトrectを取得するには?
- 5. Webアプリケーションでデリゲートタイプを使用すると便利なのは
- 6. javacriptアプリケーションでローカルファイルI/Oを管理する最も便利な方法
- 7. チャットの表示に便利なリストコンポーネントチャットのデータ
- 8. リモートリポジトリの新機能を確認する便利な方法は?
- 9. コードイグナイターで複数のデータベースをロードする便利な方法
- 10. WPFアプリケーションでWindowsフォームを表示する方法
- 11. Android XmlResourceParserの便利な使い方は?
- 12. 大規模なビットマスクを使用する便利な方法
- 13. オプションの平等をチェックする便利な方法
- 14. このようにメニューを表示すると便利ですか?
- 15. WPFでボタンコンテンツの表示を垂直にする方法は?
- 16. iphoneアプリのバイナリサイズを減らすための便利な方法
- 17. WPF - タスクマネージャで非表示になっているがアクティブなアプリケーションを表示
- 18. iPhoneで写真のスライダ/サムネイルを表示すると便利ですか?
- 19. oracleをhssqlにエクスポートする便利なショートカット方法はありますか?
- 20. モジュール(ライブラリ)をPythonプロジェクトにインポートする便利な方法はありますか?
- 21. WPFグリッドオーバーフローを非表示にする方法(CSSオーバーフローのような:非表示)
- 22. wpf mvvmでスタックパネルを非表示/表示する方法
- 23. progressCallbackはなぜ便利ですか?
- 24. iOSゲームでサウンドを再生する最も便利な方法は?
- 25. 便利なDelphiコードテンプレート
- 26. wpfでコントロールを動的に表示する方法は?
- 27. 便利なブラウザ/ POSTのためのアプリケーションとブラウザ/アーティファクトSAMLは
- 28. 複数のコントローラ間で変数を便利に保つ方法
- 29. プログレスバーを使用してWPFアプリケーションで別のウィンドウを表示する方法
- 30. ディスクリミネータテーブルをより便利にする方法
このような低レベルのネクタイの必要性は何ですか? –
これは、あなたが本当に必要とするもののより高いレベルの説明から恩恵を受けるそれらの質問の1つであり、あなたに代替案を与えることができるようです。 – Tergiver
@Aaron @Tergiver選択肢はありません。私はビジュアルを組み合わせてXpsDocumentsを作成します。私はそれらをビジュアルとして知っていますが、ビジュアルから拡張するものであってもかまいません。 – Will