Saya membuat sumber daya di file FrameRes.xaml
seperti ini:
<ResourceDictionary xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Japanese.Resources.FrameRes">
<Style x:Key="FrameBorder" TargetType="Frame">
<Setter Property="CornerRadius" Value="2" />
<Setter Property="HasShadow" Value="false" />
<Setter Property="Margin" Value="10,0" />
<Setter Property="BorderColor" Value="{DynamicResource LineColor}" />
<Setter Property="Padding" Value="0" />
<Setter Property="VerticalOptions" Value="Start" />
</Style>
</ResourceDictionary>
dan ini terkandung di dalamnya:
<?xml version="1.0" encoding="utf-8"?>
<Application xmlns:converters="clr-namespace:Japanese"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Japanese.App">
<Application.Resources>
<ResourceDictionary Source="/Resources/FooterRes.xaml" />
<ResourceDictionary Source="/Resources/FrameRes.xaml" />
</Application.Resources>
</Application>
Ketika saya mencoba mengakses ini di C# seperti ini maka gagal dan mengatakan tidak ada referensi ke FrameBorder:
var fb2 = (Style)Application.Current.Resources["FrameBorder"];
Ketika saya mencoba mengakses ini di C# seperti ini, ini berhasil:
Application.Current.Resources.TryGetValue("FrameBorder", out object frameBorder);
var fb = (Style)frameBorder;
Adakah yang tahu mengapa cara pertama tidak berhasil. Bagiku itu terlihat sama.