2 回答

TA貢獻1839條經驗 獲得超15個贊
解決方案: 正如 Ivan 所說,您可以使用Converter
請參考以下代碼。
public class ValueToTextConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if ((double)value < 20 && (double)value > 2)
{
return "Editado";
}
return "Ejemplo";
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
當數據在OneWay或TwoWay綁定中從源移動到目標時,將調用 Convert 方法。value 參數是來自數據綁定源的對象或值。該方法必須返回數據綁定目標類型的值。
在 xaml 中
<ContentPage.Resources>
<ResourceDictionary>
<local:ValueToTextConverter x:Key="ValueToText" />
</ResourceDictionary>
</ContentPage.Resources>
<StackLayout>
<ListView x:Name="listaEjemplo" HasUnevenRows="True">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Orientation="Horizontal">
<StackLayout Orientation="Vertical">
<Label Text="{Binding nombre}" Font="18"></Label>
<Slider x:Name="slider" Minimum="0" Maximum="20" />
<Label Text="{Binding Source={x:Reference slider},
Path=Value,
Converter={StaticResource ValueToText}}" TextColor="Gray"></Label>
</StackLayout>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
https://i.stack.imgur.com/Tu5Jd.gif

TA貢獻1851條經驗 獲得超5個贊
至少還有兩種方法可以做到:
Slider
Value
將與綁定TwoWay
Mode
。然后在值的設置器中更改綁定到標簽的值(在該部分類似于您在上面的代碼中所做的)綁定
Label
Value
到Slider
Value
并聲明Converter
將轉換Slider
Value
為所需Label
Value
.
- 2 回答
- 0 關注
- 146 瀏覽
添加回答
舉報