&tag(WPF/TabControl);
&tag(WPF,TabControl);
*目次 [#p2878af0]
#contents
*参考情報 [#c7556be5]

*Tips [#b074810d]
**基本)TabControlにコレクションをBindingする [#z5d849c0]
-ItemsSourceにコレクションを設定。
-ItempTemplateでヘッダー部分のカスタマイズ。
-ContentTemplateでタブの中身のカスタマイズ。

''MainWindow.xaml''
#pre{{
        <TabControl Name="tab" ItemsSource="{Binding Persons}">
            <TabControl.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Id}"/>
                </DataTemplate>
            </TabControl.ItemTemplate>
            <TabControl.ContentTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Name}"/>
                </DataTemplate>
            </TabControl.ContentTemplate>
        </TabControl>
}}

''MainWindow.xaml.cs''
#pre{{
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            this.Persons = new ObservableCollection<Person>();
            this.Persons.Add(new Person() { Id = 1, Name = "中田英寿" });
            this.Persons.Add(new Person() { Id = 2, Name = "中村俊輔" });
            this.DataContext = this;
        }

        public ObservableCollection<Person> Persons { get; set; }        
    }
}}

''Person.cs''
#pre{{
    public class Person
    {
        public int Id { get; set; }
        public string Name { get; set; }
    }
}}

**タブごとに異なる内容を描画 [#n3dc4961]
-[[TabControl.ContentTemplateSelector Property (System.Windows.Controls):http://msdn.microsoft.com/en-us/library/system.windows.controls.tabcontrol.contenttemplateselector.aspx]]
-[[WPF TabControl and DataTemplates - Stack Overflow:http://stackoverflow.com/questions/1348118/wpf-tabcontrol-and-datatemplates]]

ContentTemplateSelectorを使って切り替えるのが簡単っぽい。


**TabItemの色を変更する [#ld4d54e1]
-[[wpf controls - WPF - TabItem Background color changes when tabitem selected or hover over - Stack Overflow:http://stackoverflow.com/questions/3265140/wpf-tabitem-background-color-changes-when-tabitem-selected-or-hover-over]]
-[[c# - Change default highlight colour of TabItem in TabControl WPF - Stack Overflow:http://stackoverflow.com/questions/3889728/change-default-highlight-colour-of-tabitem-in-tabcontrol-wpf]]
-[[WPF Tab Control: Setting Tab Color? - Stack Overflow:http://stackoverflow.com/questions/2086728/wpf-tab-control-setting-tab-color]]

Templateごと定義しないとだめ?。結構めんどくさそう。

**選択をキャンセルした [#m1c626ae]
-[[wpf - Is there a way to cancel TabControl.Items.CurrentChanging? - Stack Overflow:http://stackoverflow.com/questions/4194290/is-there-a-way-to-cancel-tabcontrol-items-currentchanging/4194548#4194548]]
-[[How to prevent a TabItem from being selected &#171; Josh Smith on WPF:http://joshsmithonwpf.wordpress.com/2009/09/04/how-to-prevent-a-tabitem-from-being-selected/]]

トップ   編集 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS