0
私は、次のTabControlを持っている:WPF - バインディングされていない場合のDataTemplateプロパティの問題の要素
<TabControl ItemsSource="{Binding Tabs"}>
<TabControl.ContentTemplate>
<DataTemplate DataType="{x:Type vm:TabVM}">
<TextBox></TextBox>
<TextBox Text="{Binding SomeProperty}"></TextBox>
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>
予期しない動作が第二のTextBoxが効果的にViewModelにプロパティにバインドしながら、最初のTextBoxには、すべてのtabitems間で共有Textプロパティを持っていることです。
私の必要性は、バインディングなしでも最初のTextBoxも独立させることです。
どうすればよいですか?私はikrivのTabContent.csを使うことにしましたいくつかの試行後
** UPDATE **
。 これで見つかった唯一の問題は、TabControl.Items.Refresh()(つまりtabItemを削除した後)を呼び出すと内部キャッシュがリセットされることです。
public ContentManager(TabControl tabControl, Decorator border)
{
_tabControl = tabControl;
_border = border;
_tabControl.SelectionChanged += (sender, args) => { UpdateSelectedTab(); };
/* CUSTOM */
var view = CollectionViewSource.GetDefaultView(((TabControl)_tabControl).Items);
view.CollectionChanged += View_CollectionChanged;
}
/*
* This fix the internal cache content when calling items->Refresh() method
* */
private void View_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
{
if (e.OldItems != null)
{
/* Retrieve all tabitems cache and store to a temp list */
IList<ContentControl> cachedContents = new List<ContentControl>();
foreach (var item in _tabControl.Items)
{
var tabItem = _tabControl.ItemContainerGenerator.ContainerFromItem(item);
var cachedContent = TabContent.GetInternalCachedContent(tabItem);
cachedContents.Add(cachedContent);
}
/* rebuild the view */
_tabControl.Items.Refresh();
/* Retrieve all cached content and store to the tabitems */
int idx = 0;
foreach (var item in _tabControl.Items)
{
var tabItem = _tabControl.ItemContainerGenerator.ContainerFromItem(item);
TabContent.SetInternalCachedContent(tabItem, cachedContents[idx++]);
}
}
}
はTabControl.ItemTemplate'の代わりに、 '試してみてください'ContentTemplate' –
ItemTemplateはコンテンツではなくTabItemヘッダー用です –
アイテムテンプレートを設定する場合は、' TabControl.ItemContainerStyle'( '