Xamarin.forms Forms-在ResourceDictionary中使用StaticResource
我有一个小应用程序,其中有一个带有Syncfusion的SfChat的ContentPage,我正在尝试对其进行一些自定义,因此我使用了一个资源字典,如下所示:Xamarin.forms Forms-在ResourceDictionary中使用StaticResource,xamarin.forms,syncfusion,Xamarin.forms,Syncfusion,我有一个小应用程序,其中有一个带有Syncfusion的SfChat的ContentPage,我正在尝试对其进行一些自定义,因此我使用了一个资源字典,如下所示: <ContentPage.Resources> <syncTheme:SyncfusionThemeDictionary> <syncTheme:SyncfusionThemeDictionary.MergedDictionaries>
<ContentPage.Resources>
<syncTheme:SyncfusionThemeDictionary>
<syncTheme:SyncfusionThemeDictionary.MergedDictionaries>
<ResourceDictionary>
<x:String x:Key="SfChatTheme">CustomTheme</x:String>
<x:String x:Key="SfChatIncomingMessageAuthorFontFamily">MontserratRegular</x:String>
</ResourceDictionary>
</syncTheme:SyncfusionThemeDictionary.MergedDictionaries>
</syncTheme:SyncfusionThemeDictionary>
</ContentPage.Resources>
自定义主题
蒙特塞拉特
我的问题是“SfChatIncomingMessageAuthorFontFamily”属性需要我的应用程序资源中的字体作为静态资源,因此我如何使用{StaticResource}而不是仅仅将字体名称作为x:string传递?例如,在标签上使用它:
<ResourceDictionary>
<OnPlatform
x:Key="MediumFontFamily"
x:TypeArguments="x:String"
Android="sans-serif-medium"
iOS="HelveticaNeue-Medium" />
</ResourceDictionary>
创建样式:
<Style x:Key="MyLabel" TargetType="Label">
<Setter Property="FontFamily"
Value="{StaticResource MediumFontFamily}" />
</Style>
然后在标签中使用:
<Label Style="{StaticResource MyLabel}" Text="Hello World" />
您应该使用ResourceDictionary
中定义的SfChatIncomingMessageAuthorFontFamily
设置FontFamily
属性,如FontFamily=“{StaticResource SfChatIncomingMessageAuthorFontFamily}”
@LeoZhu MSFT您能提供更多详细信息吗?在syncfusion文档中,有人提到我需要修改ResourceDictionary,因此我必须在dictionary条目上插入staticresource字体。似乎已为自动合并提供了SyncfusionThemeDictionary
类,当您定义MontserratRegular
时,syncfusion控件将使用此FontFamily(MontserratRegular).Hi@RedZ,如果我们在字符串中提到字体系列,它将自动合并到SfChat中所需的属性。让我知道您在哪个平台上面临此问题?