gpt4 book ai didi

c# - 索引 WPF 选项卡控件

转载 作者:行者123 更新时间:2023-12-03 10:58:53 28 4
gpt4 key购买 nike

我已通过 ViewModel 属性将选项卡控件绑定(bind)到集合。我希望选项卡标题反射(reflect)它显示的项目的索引,但这似乎非常困难。是否有捷径可寻?

   <TabControl
Style ="{StaticResource GtlTabControl}"
ItemsSource="{Binding Images}"
SelectedIndex="{Binding CurrentImageIndex}">
<TabControl.ItemContainerStyle>
<Style TargetType="TabItem">
<Setter Property="Header" Value="???"/>
</Style>
</TabControl.ItemContainerStyle>
...
</TabControl>

最佳答案

您可以在 xaml 中使用 AlternationIndex。像这样的东西:

<TabControl Style ="{StaticResource GtlTabControl}"
ItemsSource="{Binding Images}"
SelectedIndex="{Binding CurrentImageIndex}"
AlternationCount="{Binding Path=Items.Count, RelativeSource={RelativeSource Self}}">
<TabControl.ItemContainerStyle>
<Style TargetType="TabItem">
<Setter Property="Header" Value="{Binding Path=(ItemsControl.AlternationIndex), RelativeSource={RelativeSource FindAncestor, AncestorType=TabItem}}"/>
</Style>
</TabControl.ItemContainerStyle>
</TabControl>

这里还发布了替代方案: Show SelectedIndex in WPF Tabcontrol header template

关于c# - 索引 WPF 选项卡控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26869076/

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