我有一个名为LOCATION_ID的表列。我想显示位于LOCATION表中的LOCATION_NAME,而不是ID。
我正在尝试实现IValueConverter,但无法弄清楚该怎么做。我在实体框架中使用WPF。
如何将ID值传递给此转换器?
我有一个方法名称GetLocationNameByID()。我将在转换器中的何处调用此方法?以及如何将返回值绑定到datagrid XAML?
实施IValueConverer
接口非常简单。在XAML中,您将具有以下内容:
<Window x:Class="CarSystem.CustomControls.AlarmDisplayer"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MyNameSpace"
DataContext="{Binding Path=MyDataContextObject, RelativeSource={RelativeSource Self}">
<Window.Resources>
<local:MyIValueConverter x:Key="Converter" />
</Window.Resoures>
<TextBox Text="{Binding Converter={StaticResource Converter} Path=MyProperty}" />
</Window>
当WPF检测的值的变化MyProperty
在MyDataContextObject
,它调用MyIValueConverter
对象的Convert
方法,并传递属性作为的值Value
参数。该Convert
方法的实现完成了它必须做的事情并返回要显示的字符串。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句