0
我有一個寬度爲auto的標籤,它綁定到一個字符串類型的屬性。轉換器只發射一次,而不是每次標籤內容變化
<Label x:Name="ExampleLabel" Content="{Binding ExampleProperty}"Height="30" Width="Auto" >
然後我有一個屬性綁定到該標籤的寬度。轉換器應該將寬度轉換爲負值。
<UserControl.Resources>
<c:PositiveToNegativeConverter x:Key="PositiveToNegativeConverter"/>
</UserControl.Resources>
"{Binding ElementName=ExampleLabel, Path=Width, Converter={StaticResource PositiveToNegativeConverter}}"
我希望轉換器在標籤內容發生變化時執行,但在應用程序加載時只會觸發一次。
這裏是我的轉換器
public class PositiveToNegativeConverter : IValueConverter
{
public object Convert(object value, Type targetType,
object parameter, CultureInfo culture)
{
return (double)value * -1;
}
public object ConvertBack(object value, Type targetType,
object parameter, CultureInfo culture)
{
return Math.Abs((double) value);
}
}
任何幫助深表感謝。謝謝。
請問,如果你綁定到'ActualWidth',而不是'Width'工作? 「寬度」是設計時間值,「實際寬度」是實時更新的運行時值。 –
它的確如此。謝啦。我不知道實際寬度:) – HaloMediaz
很酷,我會做出答案。 –