[英]How to assign DisplayMemberBinding converter in the c# code
I have a GridViewColumn
and I want to assign to its DisplayMemberBinding
property a converter.我有一个
GridViewColumn
,我想为它的DisplayMemberBinding
属性分配一个转换器。 I am able to do it in XAML, but I would like to add it from the code-behind for personals reasons.我可以在 XAML 中执行此操作,但出于个人原因,我想从代码隐藏中添加它。
When I try to assign my converter in the code it says that I need a IValueConverter
type, but it is an interface and not an object that I can create.当我尝试在代码中分配我的转换器时,它说我需要一个
IValueConverter
类型,但它是一个接口而不是我可以创建的对象。 I am able to take the converter from an other GridViewColumn
, but I won't always have the converter that I want assigned to another one.我可以从另一个
GridViewColumn
获取转换器,但我不会总是将我想要分配给另一个转换器的转换器。
<!-- XAML code that works and that I want to implement in the code-behind -->
<GridViewColumn x:Name="intensityColumnStatus" Header="Intensity" DisplayMemberBinding="{Binding Intensity,Converter={StaticResource converter}}" />
// Code-behind that I can't get to work
Binding visibilityBinding = new Binding("isPlaneComing");
visibilityBinding.Converter = ???;
I know that I'm maybe missing some information, so if you need more, please just ask :)我知道我可能遗漏了一些信息,所以如果您需要更多信息,请询问:)
Alright, I figured it out.好吧,我想通了。 I was trying to just put
我试图把
visibilityBinding.Converter = myConverterClass;
but in reality I needed to simply put但实际上我需要简单地说
visibilityBinding.Converter = new myConverterClass();
I hope this can help someone in the future.我希望这可以帮助将来的某个人。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.