代码之家  ›  专栏  ›  技术社区  ›  tbischel

绑定到用户控件属性的WPF

  •  1
  • tbischel  · 技术社区  · 14 年前

            <TabControl ItemsSource="{Binding FooList}">
                <TabControl.ItemTemplate>
                    <DataTemplate>
                        <TabItem Header="{Binding Name}">
                            ???
                        </TabItem>
                    </DataTemplate>
                </TabControl.ItemTemplate>
            </TabControl>
    

    foo observateCollection中的类看起来像。。。

        public class IFoo
        {
            public String Name { get; set; }
            public UserControl Display { get; set; }
            ...
        }
    

    我不知道的是如何将display属性添加到??? 在XAML中。有办法做到这一点吗(尽量避免从代码后面做这件事)?

    1 回复  |  直到 14 年前
        1
  •  2
  •   Abe Heidebrecht    14 年前

    你需要做的是使用 ItemContainerStyle TabControl :

    <TabControl ItemsSource="{Binding FooList}">
        <TabControl.ItemContainerStyle>
            <Style TargetType="{x:Type TabItem}">
                <Setter Property="Header" Value="{Binding Name}" />
                <Setter Property="Content" Value="{Binding Display}" />
            </Style>
        </TabControl.ItemContainerStyle>
    </TabControl>