-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Polygon Shape doesn't work with DynamicResource color binding #11691
Comments
The type supported by the Shapes |
@jsuarezruiz so you'd like TypeConverters to be applied with DynamicResource, or any kind of Binding too ? |
I define a SolidColorBrush entry in my App.xaml and reference this Brush in my Polygon I can only use a fixed color or StaticResource Color, as soon as I change the Brush Color to a DynamicResource Color it doesn't render the Polygon. |
Could you take a look to this modified sample: |
I took a look, but what if I wanted to do it like how it is in this modified modified sample: |
@bdgza Thanks for the new modified sample. Now I see the issue!. Will answer here when I have the fix. |
@BurkusCat Thanks for the feedback, I will review the issue changing the |
Xamarin.Forms 5.0.0.1931
|
I'm having issues with the brush not changing using In DarkTheme.xaml <?xml version="1.0" encoding="UTF-8" ?>
<ResourceDictionary
x:Class="EnigmatiKreations.Framework.Controls.DarkTheme"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Color x:Key="PrimaryColor">Black</Color>
<Color x:Key="AccentColor">WhiteSmoke</Color>
<Color x:Key="TertiaryColor">#484848</Color>
<Color x:Key="CardEvenColor">#212121</Color>
</ResourceDictionary> In LightTheme.xaml <?xml version="1.0" encoding="UTF-8" ?>
<ResourceDictionary
x:Class="EnigmatiKreations.Framework.Controls.LightTheme"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Color x:Key="PrimaryColor">WhiteSmoke</Color>
<Color x:Key="AccentColor">Black</Color>
<Color x:Key="TertiaryColor">DarkGray</Color>
<Color x:Key="CardEvenColor">GhostWhite</Color>
</ResourceDictionary> In Themes.xaml <?xml version="1.0" encoding="utf-8" ?>
<ResourceDictionary
x:Class="EnigmatiKreations.Framework.Controls.Themes"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<!-- https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/theming/theming -->
<SolidColorBrush x:Key="PrimaryBrush" Color="{DynamicResource PrimaryColor}" />
<SolidColorBrush x:Key="AccentBrush" Color="{DynamicResource AccentColor}" />
<SolidColorBrush x:Key="TertiaryBrush" Color="{DynamicResource TertiaryColor}" />
<SolidColorBrush x:Key="QuaternaryBrush" Color="{DynamicResource CardEvenColor}" />
[.... more styles here using the brushes and colors ...]
</ResourceDictionary> In App.xaml <?xml version="1.0" encoding="utf-8" ?>
<Application
x:Class="ControlsGallery.App"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:Controls="clr-namespace:EnigmatiKreations.Framework.Controls;assembly=EnigmatiKreations.Framework.Controls">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!-- Imports the app themes (color palettes, and default styles for native controls) -->
<!-- Every other template and control depends on this import -->
<Controls:Themes />
<!-- Imports data templates and templates to be reused across the app -->
<!-- They themselves make use of themes -->
<Controls:Templates />
<!-- Imports XAML styles and templates for custom controls, templated controls and inherited controls from the app -->
<!-- They themselves make use of templates and themes -->
<Controls:GenericControls />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
<!-- Default is set apart to identify it easily when changing it dynamically with switch -->
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<Controls:DarkTheme />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application> In MainPage.xaml <!-- (changing the Fill expression to Fill="{StaticResource AccentBrush}" to shows the same behavior -->
<Path
Aspect="UniformToFill"
Data="M19,13H13V19H11V13H5V11H11V5H13V11H19V13Z"
Fill="{DynamicResource AccentBrush}"
HeightRequest="64"
HorizontalOptions="Center"
VerticalOptions="Center"
WidthRequest="64" /> In MainPage.xaml.cs, the code that dynamically changes the app's theme for Xamarin.Forms public MainPage()
{
InitializeComponent();
BindingContext = this;
}
private void Switch_Toggled(object sender, ToggledEventArgs e)
{
var themeMergedDictionary = Application.Current.Resources.MergedDictionaries.Where(d => d.MergedDictionaries.Count == 1).FirstOrDefault();
if (themeMergedDictionary != null) themeMergedDictionary.MergedDictionaries.Clear();
if (e.Value)
{
Application.Current.UserAppTheme = OSAppTheme.Light;
themeMergedDictionary.MergedDictionaries.Add(new LightTheme());
}
else
{
Application.Current.UserAppTheme = OSAppTheme.Dark;
themeMergedDictionary.MergedDictionaries.Add(new DarkTheme());
}
} It only works if I declare the brushes directly with static color values in Working LightTheme.xaml <?xml version="1.0" encoding="UTF-8" ?>
<ResourceDictionary
x:Class="EnigmatiKreations.Framework.Controls.LightTheme"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Color x:Key="PrimaryColor">WhiteSmoke</Color>
<Color x:Key="AccentColor">Black</Color>
<Color x:Key="TertiaryColor">DarkGray</Color>
<Color x:Key="CardEvenColor">GhostWhite</Color>
<SolidColorBrush x:Key="PrimaryBrush" Color="WhiteSmoke" />
<SolidColorBrush x:Key="AccentBrush" Color="Black" />
<SolidColorBrush x:Key="TertiaryBrush" Color="DarkGray" />
<SolidColorBrush x:Key="QuaternaryBrush" Color="GhostWhite" />
</ResourceDictionary> Working DarkTheme.xaml <?xml version="1.0" encoding="UTF-8" ?>
<ResourceDictionary
x:Class="EnigmatiKreations.Framework.Controls.DarkTheme"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Color x:Key="PrimaryColor">Black</Color>
<Color x:Key="AccentColor">WhiteSmoke</Color>
<Color x:Key="TertiaryColor">#484848</Color>
<Color x:Key="CardEvenColor">#212121</Color>
<SolidColorBrush x:Key="PrimaryBrush" Color="Black" />
<SolidColorBrush x:Key="AccentBrush" Color="WhiteSmoke" />
<SolidColorBrush x:Key="TertiaryBrush" Color="#484848" />
<SolidColorBrush x:Key="QuaternaryBrush" Color="#212121" />
</ResourceDictionary> Is this a normal behaviour? If so, why? Can someone please explain? |
Description
Updating to XF 4.8 from 4.7 the DynamicResource fill color binding on the Polygon shape is no longer recognized. It still works with a fixed color.
Steps to Reproduce
Expected Behavior
The DynamicResource color binding is used to fill the Polygon.
Actual Behavior
The Polygon is not drawn at all.
Basic Information
Screenshots
4.7:
4.8:
Reproduction Link
PolygonDynamicColor.zip
The text was updated successfully, but these errors were encountered: