ライブラリ コントロールを含む散布図を使用している場合。ユーザーは、要素をライブラリ コンテナーからスキャッター ビューにドラッグできます。その後、ユーザーは画像を削除できます。
ドラッグ テンプレートとしてビュー ボックス内のサーフェス ボタンとイメージを含むスタイルを作成しました。
問題は、表面ボタンのクリック機能にありますか? 画像を削除するには何を書けばよいですか。
ライブラリ コントロールを含む散布図を使用している場合。ユーザーは、要素をライブラリ コンテナーからスキャッター ビューにドラッグできます。その後、ユーザーは画像を削除できます。
ドラッグ テンプレートとしてビュー ボックス内のサーフェス ボタンとイメージを含むスタイルを作成しました。
問題は、表面ボタンのクリック機能にありますか? 画像を削除するには何を書けばよいですか。
ScatterViewItem 全体を削除しますか、それとも画像だけを削除してボタンを保持しますか? 一般に、次のメソッドで Visual Ancestor を見つけて ScatterViewItems を削除します。
/// <summary>
/// Attempts to get an ancestor of the passed-in element with the given type.
/// </summary>
/// <typeparam name="T">Type of ancestor to search for.</typeparam>
/// <param name="descendent">Element whose ancestor to find.</param>
/// <param name="ancestor">Returned ancestor or null if none found.</param>
/// <returns>True if found, false otherwise.</returns>
public static T GetVisualAncestor<T>(DependencyObject descendent) where T : class
{
T ancestor = null;
DependencyObject scan = descendent;
ancestor = null;
while (scan != null && ((ancestor = scan as T) == null))
{
scan = VisualTreeHelper.GetParent(scan);
}
return ancestor;
}
その後、アイテム コレクションから SVI を削除できます。