Bug 39062 - Setters are not exposed from a BaseResourceKey in an Application Resource Dictionary
Summary: Setters are not exposed from a BaseResourceKey in an Application Resource Dic...
Status: RESOLVED NOT_REPRODUCIBLE
Alias: None
Product: Forms
Classification: Xamarin
Component: iOS ()
Version: 2.0.0
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-02-23 20:32 UTC by Mark Fredrickson
Modified: 2017-01-26 14:50 UTC (History)
1 user (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
can't reproduce (183.95 KB, image/png)
2017-01-26 14:49 UTC, Stephane Delcroix
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED NOT_REPRODUCIBLE

Description Mark Fredrickson 2016-02-23 20:32:25 UTC
The following Xaml defines my application resource dictionary and I reference the FontSize setter in my app. With Android the setter is exposed but with iOS it is not. The TextColor and BackgroundColor are exposed but none of the base setters are.
            
<Forms:Application
    xmlns="http://xamarin.com/schemas/2014/forms"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:Forms="clr-namespace:Xamarin.Forms;assembly=Xamarin.Forms"
    xmlns:BlueFire="clr-namespace:BlueFire;assembly=BlueFire"
    x:Class="BlueFire.Startup">

    <Application.Resources>
        <ResourceDictionary>

            <!-- Buttons -->
            <Style x:Key="ButtonStyle" TargetType="Button">
                <Setter Property="BorderRadius" Value="8" />
                <Setter Property="HeightRequest" Value="42" />
                <Setter Property="BorderColor" Value="Black"/>
                <Setter Property="BorderWidth" Value="2" />
                <Setter Property="FontSize" Value="12" />
            </Style>
            <!-- Red Button -->
            <Style x:Key="RedButtonStyle" TargetType="Button"  BaseResourceKey="ButtonStyle">
                <Setter Property="TextColor" Value="White" />
                <Setter Property="BackgroundColor" Value="Red" />
            </Style>
            <!-- Green Button -->
            <Style x:Key="GreenButtonStyle" TargetType="Button"  BaseResourceKey="ButtonStyle">
                <Setter Property="TextColor" Value="White" />
                <Setter Property="BackgroundColor" Value="Green" />
            </Style>
            <!-- Blue Button -->
            <Style x:Key="BlueButtonStyle" TargetType="Button"  BaseResourceKey="ButtonStyle">
                <Setter Property="TextColor" Value="White" />
                <Setter Property="BackgroundColor" Value="Blue" />
            </Style>

        </ResourceDictionary>

    </Application.Resources>

</Forms:Application>
Comment 1 Stephane Delcroix 2016-02-24 12:11:57 UTC
Hi Mark,

I'm not sure I understand what your problem is. Could you please attach a semple project showcasing the error, or at least better describe

 1. What you're doing
 2. What's the expected results
 3. What's the observed results

Thanks a lot

The XF team
Comment 2 Mark Fredrickson 2016-02-25 15:13:41 UTC
The following works just fine in my Android app but not in my iOS app. In iOS, the FontSize setter is not found in the FindSetterValue routine. If you break and look at the button control the only setters in the collection are TextColor and BackgroundColor. The inherited setters (BorderRadius, HeightRequest, BorderColor, BorderWidth, and FontSize) are not there. They are there in Android.

Button Xaml in my form:

<Button x:Name="ConnectButton" Clicked="ConnectButton_Clicked" Style="{DynamicResource GreenButtonStyle}"  />

Code in my app:

Controls.SetText(ConnectButton, "Connect", 35);

Code in my Controls library:

private static object FindSetterValue(Xamarin.Forms.View Control, String SetterName)
{
    foreach (Setter s in Control.Style.Setters)
        if (s.Property.PropertyName == SetterName)
            return s.Value;

    return null;
}

private static Single GetFontSize(Xamarin.Forms.View Control)
{
    return Convert.ToSingle(FindSetterValue(Control, "FontSize"));
}

public static void SetText(Button Control, String Text, Single WidthRequest)
{
    Control.Text = Text;
    Control.FontSize = GetFontSize(Control);
    Control.WidthRequest = WidthRequest;
}
Comment 3 Stephane Delcroix 2017-01-26 14:49:14 UTC
Created attachment 19488 [details]
can't reproduce

As you can see, it works fine for me in both Android and iOS using XF 2.3.3, both with {StaticResource} and {DynamicResource}.
Comment 4 Stephane Delcroix 2017-01-26 14:50:54 UTC
I can not reproduce that bug and no valid reproduction case was attached to this bug in 11months.
I guess the bug is no longer present in latest version of XF, and thus closing this bug.