xamarin.form databinding

<StackLayout>
        <Label x:Name="label1" 
               Text="{Binding Source={x:Reference slider1},Path=Value,StringFormat='Value is {0:F2}'}" 
               FontSize="{Binding Source={x:Reference slider1},Path=Value}"
               VerticalOptions="Center" HorizontalOptions="Center"></Label>
        <Slider x:Name="slider1" Maximum="100" Minimum="1" Value="1"></Slider>
    </StackLayout>

  或者使用BindingContext

<StackLayout>
        <Label x:Name="label1" 
            BindingContext="{Binding Source={x:Reference slider1}}"
            Text="{Binding Path=Value,StringFormat='Value is 0:F2'}"
            FontSize="{Binding Path=Value}"
        VerticalOptions="Center" HorizontalOptions="Center"></Label>
        <Slider x:Name="slider1" Maximum="100" Minimum="1" Value="1"></Slider>
    </StackLayout>

  Text="{Binding Source={x:Reference slider1},Path=Value,StringFormat='Value is {0:F2}'}" 

需要指定Source和Path,有的时候需要指定StringFormat

猜你喜欢

转载自www.cnblogs.com/jiecaoge/p/10020458.html