一直用這個問題搜索幾個小時,並且無法看到我出錯的地方。IValueCOnverter不能正常工作
我有以下轉換器,它只是返回Brushes.Red(已嘗試Colors.Red)以及但仍然沒有運氣。
public class ColorConverter : IValueConverter
{
private static ColorConverter instance = new ColorConverter();
public static ColorConverter Instance
{
get
{
return instance;
}
}
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return Brushes.Red;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new Exception("The method or operation is not implemented.");
}
}
現在在我的XAML我有以下代碼:
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding Value}" TextAlignment="Center" Foreground="{Binding Path=color, Converter={x:Static local:ColorConverter.Instance}}" Margin="2"/>
</StackPanel>
我已經設置格蘭以下命名空間的頂部:
xmlns:local="clr-namespace:Dashboard"
現在我有一個綁定下面的類到堆棧面板:
public class MyClass : INotifyPropertyChanged
{
public String Value;
public Color color;
// Declare the PropertyChanged event
public event PropertyChangedEventHandler PropertyChanged;
public void NotifyPropertyChanged(String info)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(info));
}
}
}
數據綁定(值)工作得很好,但轉換器不想踢,我試圖在covnerter的Convert方法中設置一個斷點,但調試時不會觸發它,它就好像我的調試器沒有被調用。
任何人都可以對此有所瞭解嗎?
是啊,我甚至懶得去看他們的聲明,因爲它聽起來像一切,但轉換器工作。 :) – Dave 2010-02-11 14:32:43