最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Resource Dictionary Not Loading After Enabling Compiled Bindings in .Net MAUI - Stack Overflow

programmeradmin1浏览0评论

Style for BoxView:

<Style x:Key="LabeledFieldPlaceholderBoxViewStyle"
       TargetType="BoxView">
        <Setter Property="HeightRequest"
                Value="23"/>
        <Setter Property="Margin"
                Value="0, 0, 0, 0"/>
        <Setter Property="Color"
                Value="Transparent"/>
        <Setter Property="BackgroundColor"
                Value="Transparent"/>
</Style>

CommonTempaltes.xaml

<ResourceDictionary
    x:Class="Same.Mobile.UI.Core.Resources.CommonTemplates"
    xmlns=";
    xmlns:x=";
    xmlns:baseclasses="clr-namespace:Same.Mobile.UI.Core.BaseClasses"
    xmlns:behaviors="clr-namespace:Same.Mobile.UI.Core.Behaviors"
    xmlns:const="clr-namespace:Same.Mobile.UI.Core;assembly=Same.Mobile.UI.Core"
    xmlns:ctrls="clr-namespace:Same.Mobile.UI.Core.Controls;assembly=Same.Mobile.UI.Core"
    xmlns:helper="clr-namespace:Same.Mobile.UI.Core.Helpers;assembly=Same.Mobile.UI.Core"
    xmlns:model="clr-namespace:Same.Mobile.UI.Core.Abstractions.Models;assembly=Same.Mobile.UI.Core.Abstractions"
    xmlns:toolkit=";>

    <!--  ControlTemplate  -->
    <ControlTemplate x:Key="EntryFieldTemplate">
        <VerticalStackLayout
            x:DataType="ctrls:EntryField"
            ClassId="_entryFieldLayout"
            HorizontalOptions="{TemplateBinding Path=HorizontalOptions}"
            VerticalOptions="{TemplateBinding Path=VerticalOptions}"
            WidthRequest="{TemplateBinding Path=WidthRequest}">

            <!--  Label - visibility is determined by converter (see class)  -->
            <Label
                x:Name="_entryFieldLabel"
                AutomationId="LabelText"
                ClassId="_entryFieldLabel"
                Style="{TemplateBinding Path=LabelTextStyle}"
                Text="{TemplateBinding Path=LabelText}"/>

            <BoxView
                AutomationId="BoxViewPlaceholder"
                IsVisible="{Binding Path=IsVisible, Source={Reference Name=_entryFieldLabel}, Converter={StaticResource InvertedBoolConverter}}"
                Style="{DynamicResource Key=LabeledFieldPlaceholderBoxViewStyle}">
                <BoxView.Triggers>
                    <DataTrigger TargetType="BoxView"
                                 Binding="{Binding Path=IsVisible, Source={Reference Name=_entryFieldLabel}, Converter={StaticResource Key=InvertedBoolConverter}}"
                                 Value="True">
                        <Setter Property="HeightRequest"
                                Value="23"/>
                    </DataTrigger>
                    <DataTrigger TargetType="BoxView"
                                 Binding="{Binding Path=IsVisible, Source={Reference Name=_entryFieldLabel}, Converter={StaticResource Key=InvertedBoolConverter}}"
                                 Value="False">
                        <Setter Property="HeightRequest"
                                Value="1"/>
                    </DataTrigger>
                </BoxView.Triggers>
            </BoxView>

            <Entry
                AutomationId="FieldText"
                ClassId="_entryFieldEntry"
                HeightRequest="{TemplateBinding Path=FieldHeightRequest}"
                IsEnabled="{TemplateBinding Path=IsEnabled}"
                IsPassword="{TemplateBinding Path=IsPassword}"
                Keyboard="{TemplateBinding Path=Keyboard}"
                Placeholder="{TemplateBinding Path=Placeholder}"
                Style="{TemplateBinding Path=EntryStyle}"
                Text="{TemplateBinding Path=Text,
                                       Mode=TwoWay}"
                WidthRequest="{TemplateBinding Path=FieldWidthRequest}"/>

            <Label
                AutomationId="ValidationResult"
                IsVisible="{TemplateBinding Path=ValidationResult.IsValid,
                                            Converter={StaticResource Key=InvertedBoolConverter}}"
                Style="{DynamicResource Key=SmallValidationErrorLabelStyle}"
                Text="{TemplateBinding Path=ValidationResult,
                                       Converter={StaticResource Key=ValidationErrorsLabelConverter}}"/>
        </VerticalStackLayout>
    </ControlTemplate>
    <Style TargetType="ctrls:EntryField">
        <Setter Property="ControlTemplate"
                Value="{StaticResource Key=EntryFieldTemplate}"/>
    </Style>

</ResourceDictionary>

Using like this in cosuming app.

<Application
    x:Class="CoreTestApp.App"
    xmlns=";
    xmlns:x=";
    xmlns:commonResources="clr-namespace:Same.Mobile.UI.Core.Resources;assembly=Same.Mobile.UI.Core"
    xmlns:local="clr-namespace:CoreTestApp">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Resources/Styles/Colors.xaml" />
                <ResourceDictionary Source="Resources/Styles/Styles.xaml" />
                <commonResources:CommonStyles />
                <commonResources:CommonTemplates />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

This template is working fine before moving to compiled bindings. To use compiled bindings I have enabled this from csproject file: <MauiEnableXamlCBindingWithSourceCompilation>true</MauiEnableXamlCBindingWithSourceCompilation>

After enabling this I have noticed that BoxView control's height is not changing dynamically, so I have added the trigger to handle its height dynamically. Now if I add this project locally or use .dll file of it in consuming project than it did work fine. But when this changes got publised and I got updated version of nuget package (for this) it's not working in consuming project.

To make sure this work I have added this code in .csproject file already but still it did not works when it gets published and I use it as nuget.

<ItemGroup>
  <None Include="Resources\CommonStyles.xaml" Pack="True" PackagePath="buildTransitive\Resources\" />
  <None Include="Resources\CommonTemplates.xaml" Pack="True" PackagePath="buildTransitive\Resources\" />
</ItemGroup>
<ItemGroup>
  <MauiXaml Update="Resources\CommonStyles.xaml" Pack="True" PackagePath="buildTransitive\Resources\" />
  <MauiXaml Update="Resources\CommonTemplates.xaml" Pack="True" PackagePath="buildTransitive\Resources\" />
</ItemGroup>

This work fine if I add this project reference locally in consuming project or use debug .dll file.

How to handle this?

发布评论

评论列表(0)

  1. 暂无评论