Xamarin表单按钮带有加载指示灯

Dam*_*sik 1 xamarin xamarin.forms

我大约一周就进入了Xamarin,对于在按钮内加载图标的可能性有疑问.

我想实现类似的东西:https: //jsfiddle.net/mr8fwtcv/

我试图用FontAwesome实现这种效果,但是在设置动画时遇到问题,所以在解决方案中使用Activity Indicator也不错.

我的按钮放在Stack Layout中,这是代码:

var loginButton = new Button
{
    BackgroundColor = Color.FromHex("689F38"),
    TextColor = Color.White,
    HeightRequest = 46,
    Text = "Log in",
    FontAttributes = FontAttributes.Bold,
    FontSize = 18,
    Margin = margin
};
Run Code Online (Sandbox Code Playgroud)

我一直在寻找一些插件/解决方案,但找不到任何.提前致谢.

Roh*_*ews 5

您必须使用布局才能在其中包含多个控件.如果你不是在寻找CustomRenderers,那么你可以做的就是拥有一个RelativeLayout,并且在Button和Activity Indicator里面.您还必须为按钮文本编写一个转换器,当IsBusy为true时,该文本将文本设置为string.Empty.

例如:

<StackLayout>
    <ActivityIndicator IsVisible="{Binding IsBusy}" IsRunning="{Binding IsBusy}" />
    <Button Text="{Binding ButtonText, Converter={StaticResource ButtonTextConverter}, ConverterParameter={Binding IsBusy} />
</StackLayout>
Run Code Online (Sandbox Code Playgroud)

此外,如果您计划在多个位置使用此功能,则可以将其创建为自定义控件.

您可以在此处查看自定义控制代码.

完整的项目可在此处获得.