【问题标题】:XAML there's the way to binding the array's index in a Style? [duplicate]XAML 有没有将数组的索引绑定到样式中的方法? [复制]
【发布时间】:2020-12-07 19:45:58
【问题描述】:
可以绑定数组的索引,例如:
<Style x:Key="NameButtonStyle" TargetType="Button">
<Setter Property="Visibility" Value="{Binding Array[{Binding custom property index}]}/>
</Style>
【问题讨论】:
标签:
wpf
xaml
binding
styles
【解决方案1】:
仅当“索引”由常量指定时,例如 1:
<Style x:Key="NameButtonStyle" TargetType="Button">
<Setter Property="Visibility" Value="{Binding Array[1]}/>
</Style>
您不能将上面示例中的1 替换为在运行时解析的动态值。如果需要,您必须使用转换器或公开返回 Array[x] 的属性,其中 x 表示动态值。