我有一個Listview(綁定到ObservableCollection),所有元素都基於IValueConverter進行啓用/禁用計算。Xamarin:如何在通知調用中調用IValueConverter
下面是的IValueConverter代碼...
public class StateCheckConverter: IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var result = false;
if (value != null)
{
var element = value as Element;
if (element.Status != Status.Pending)
result = true;
}
return result;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return value;
}
}
現在我已經收到了通知(從MessageCenter)和呼叫的要素之一的恢復狀態發生了變化。我能夠改變元素的文本和值(比如標籤,圖片使用INotifyPropertyChanged)。但是,如何調用相應的IValueConverter並更新ObservableCollection?
謝謝。
UPDATE:
<ContentPage.Resources>
<ResourceDictionary>
<vm:StateCheckConverter x:Key="transmissionStateCheck" />
</ResourceDictionary>
</ContentPage.Resources>
<Label x:Name="lblLocked"
IsVisible="{Binding ., Converter={StaticResource transmissionStateCheck}, Mode=TwoWay}"
HorizontalTextAlignment="Center"
BackgroundColor="Gray"
Opacity="0.75"
Text="LOCKED"
TextColor="White"
FontSize="35"
/>
你如何使用轉換器?請將代碼綁定到項目的「IsEnabled」狀態。 – Emad
@Emad我已經更新了代碼.. – Xander