gpt4 book ai didi

c# - 绑定(bind)的 TabControl 跨选项卡重复相同的内容或控件

转载 作者:太空宇宙 更新时间:2023-11-03 22:54:25 25 4
gpt4 key购买 nike

在下面的示例中,当数据绑定(bind)到选项卡控件时,它正确地具有每个数据的选项卡标题,但选项卡内容始终相同;和绑定(bind)到的最后一项。

“Frank Wright”的“Wright”出现在每一页上。

怎么了?人们希望每个页面上都有不同的控件,而不是共享一个控件或重复数据。

enter image description here

<Page.Resources>
<model:People x:Key="People">
<model:Person First="Joe"
Last="Smith"
Phone="303-555-5555" />
<model:Person First="Jenny"
Last="Johnson"
Phone="720-867-5309" />
<model:Person First="Frank"
Last="Wright"
Phone="202-555-5555" />
</model:People>
</Page.Resources>
<TabControl ItemsSource="{StaticResource People}">
<TabControl.ItemContainerStyle>
<Style TargetType="TabItem">
<Setter Property="Header"
Value="{Binding First}" />
<Setter Property="Content">
<Setter.Value>
<TextBox Text="{Binding Last}" />
</Setter.Value>
</Setter>
</Style>
</TabControl.ItemContainerStyle>
</TabControl>

public class People : List<Person> { }

public class Person
{
public string First { get; set; }
public string Last { get; set; }
public string Phone { get; set; }
}

最佳答案

您想设置ContentTemplate,而不是Content:

<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<StackPanel Orientation="Vertical">
<TextBox Text="{Binding Last}" />
<Label Content="{Binding Phone}" />
</StackPanel>
</DataTemplate>
</Setter.Value>
</Setter>

关于c# - 绑定(bind)的 TabControl 跨选项卡重复相同的内容或控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46099370/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com