-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Binding doesn't work #159
Comments
Same for me. It works on Android but not on iOS. |
I found some workaround. Results:
|
My solution is to use some attached property. Creating this property class: public class FasIcon
{
private static readonly string SpecialInitialValue = DateTime.UtcNow.ToLongTimeString();
private static bool isIOS => Device.RuntimePlatform != Device.iOS;
private static bool IsInitial(object value) => object.ReferenceEquals(value, SpecialInitialValue);
public static readonly BindableProperty IconProperty = BindableProperty.CreateAttached(
"Icon", typeof(string), typeof(FasIcon), SpecialInitialValue,
propertyChanged: OnPropertyChanged);
private static void OnPropertyChanged(BindableObject bindable, object oldValue, object newValue)
{
if (isIOS || IsInitial(oldValue))
{
SetValue(bindable, newValue);
}
else
{
SetValue(bindable, RemovePrefix((string)newValue));
}
}
private static void SetValue(BindableObject bindable, object value)
{
bindable.SetValue(IconButton.TextProperty, value);
}
private static string RemovePrefix(string value)
{
var pos = value.IndexOf('-');
return pos > 0 ? value.Substring(pos + 1) : value;
}
public static string GetIcon(BindableObject element) => (string) element.GetValue(IconProperty);
public static void SetIcon(BindableObject element, string value) => element.SetValue(IconProperty, value);
} Use it like this. I used it with triggers: <Style x:Key="PlayPauseButtonStyle" TargetType="iconize:IconButton" BasedOn="{StaticResource CommandbarButtonStyle}">
<Style.Triggers>
<DataTrigger TargetType="iconize:IconButton" Binding="{Binding PlayPauseIconState}" Value="Pause">
<Setter Property="views:FasIcon.Icon" Value="fas-pause" />
</DataTrigger>
<DataTrigger TargetType="iconize:IconButton" Binding="{Binding PlayPauseIconState}" Value="Play">
<Setter Property="views:FasIcon.Icon" Value="fas-play" />
</DataTrigger>
</Style.Triggers>
</Style> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Binding
Text
property ofIconButton
doesn't work as expected(on iOS).I created the following XAML, and dynamically changed the value to "fas-stop" from "fas-play", but saw "f...stop-icon" instead of "stop-icon".
I confirmed the text is right, and that a button initially set "fas-stop" works fine to conclude the binding mechanism of the component is simply broken.
I tried to reproduce that bug by modifying your sample projects, only to fail to build just after checkout.
ADD: Application dependency:
The text was updated successfully, but these errors were encountered: