如何在索引绑定路径中使用自定义枚举值 [英] How to use custom enum values in indexed binding path
问题描述
大家好!
WPF对我来说是新手,我暂时停滞不前。
我有一个枚举:
Hi All!
WPF is new to me, and I am stalled at a point.
I have an enum:
[Flags]
public enum Toners
{
black = 1,
cyan = 2,
magenta = 4,
yellow = 8
}
和一个类,它具有基于此枚举的索引器属性:
and a class, that has an indexer property based on this enum:
public string this[Toners toner]
{
get
{
return this.TonerLevels.ContainsKey(toner) ? this.TonerLevels[toner].ToString() : String.Empty;
}
}
太棒了,但是当绑定一个文本列时我得不到任何结果:
Great, but I can''t get any result when binding a textcolumn to it:
<DataGridTextColumn Header="Black" Binding="{Binding [Toners.blank]}" Width="100" CellStyle="{StaticResource CenterCellStyle}"/>
同样的sni当索引的类型为int时,ppet正在工作,我将其引用为 {Binding [1]}
请指导我,如果可能的话,如何让它以enum方式工作。
[更新]
我也试过导入包含枚举的命名空间直接进入xaml,并使用。引用枚举值。和:符号,但仍然没有结果。
最糟糕的是,没有错误信息:(,只有空的结果。我想它会布里格我更接近,如果我能以某种方式增加xaml编译的冗长,但我不知道如何。
谢谢。
The same snippet is working when the index is of type int, and I am referencing it as {Binding [1]}
Please guide me, how to make it work in the enum way if possible.
[Update]
I have also tried importing the namespace containing the enum directly into the xaml, and referencing the enum value both with "." and ":" notation, but still no result.
The worst is, that there is no error message either :(, only empty result. I suppose it would brig me closer, if I could increase somehow the verbosity of the xaml compilation, but I have no idea how.
Thank you.
推荐答案
试试这个,
Binding ={Binding [(int)Toners.blank]}
希望这对你有用。
try this,
Binding="{Binding [(int)Toners.blank]}"
hopes this work for you.
这篇关于如何在索引绑定路径中使用自定义枚举值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!