用于集合的 WPF 绑定转换器
我有一个用于显示文件结构的 WPF 树视图。每个树项目都有一个枚举集合来确定项目的自定义状态。 IE ObservableCollection
当树项具有这些状态之一时,我会显示几个省略号...类似这样:
<Ellipse Margin="3,0" Visibility="{Binding StatusCollection, Converter={StaticResource VisibilityConverter}}" StrokeThickness="1" Stroke="Black" Width="12" Height="12" Fill="Red" />
有没有一种方法可以对多个省略号使用相同的转换器来检查特定状态...也许通过争论?现在在转换器中,我循环遍历集合寻找特定的枚举...这样做,我必须为创建的每个枚举创建一个新的转换器,这并不理想。
更好的是,我将如何为树视图项中的每个状态动态创建省略号?
I have a WPF treeview used to display a file structure. Each treeitem has a collection of enums to determine custom status' of the item. I.E. ObservableCollection<enumType> statusCollection;
I have several ellipses that are displayed when a treeitem has one of these status... something like this:
<Ellipse Margin="3,0" Visibility="{Binding StatusCollection, Converter={StaticResource VisibilityConverter}}" StrokeThickness="1" Stroke="Black" Width="12" Height="12" Fill="Red" />
Is there a way I can use the same Converter for multiple ellipses to check for a specific status... via an argument perhaps? Right now in the Converter, i loop through the collection looking for the specific enum... doing this, I would have to create a new Converter for each enum created, which is not ideal.
Better yet, how would I go about dynamically creating Ellipses for each status in a treeviewitem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将
ConverterParameter
添加到Binding
:然后,这将作为
参数
传递到您的IValueConverter
(第三个参数)然后您可以根据需要在转换器中使用该参数。
You could add a
ConverterParameter
to theBinding
:This will then be passed into your
IValueConverter
as theparameter
(third parameter) inYou can then use the parameter within your converter however you need.