私のプログラムではtabItems
、ビュー モデルにコマンドがバインドされています。tabItem
新しいtabItem
. _ このプログラムのユーザーは new を追加できるため、これを行う必要がありますtabItems
。
現在、私はCopying a TabItem with an MVVM structure というGrid
質問を使用していますが、関数がを使用してオブジェクトをコピーしようとすると問題が発生するようですdependencyValue
。
私が使用しているクラス:
public static class copyTabItems
{
public static IList<DependencyProperty> GetAllProperties(DependencyObject obj)
{
return (from PropertyDescriptor pd in TypeDescriptor.GetProperties(obj, new Attribute[] { new PropertyFilterAttribute(PropertyFilterOptions.SetValues) })
select DependencyPropertyDescriptor.FromProperty(pd)
into dpd
where dpd != null
select dpd.DependencyProperty).ToList();
}
public static void CopyPropertiesFrom(this FrameworkElement controlToSet,
FrameworkElement controlToCopy)
{
foreach (var dependencyValue in GetAllProperties(controlToCopy)
.Where((item) => !item.ReadOnly)
.ToDictionary(dependencyProperty => dependencyProperty, controlToCopy.GetValue))
{
controlToSet.SetValue(dependencyValue.Key, dependencyValue.Value);
}
}
}
プログラムに到達すると、「指定された要素はすでに別の要素の論理的な子です。最初に切断してください」というメッセージがスローdependencyValue
されます。{[Content, System.Windows.Controls.Grid]}
InvalidOperationException was Unhandled
これは何を意味するのでしょうか?Grid
これは WPFの一般的な問題ですか? 私のプログラムに、これを引き起こしていることに気付いていない何かがありますか?