ContentView中使用的App StaticResource会抛出异常

时间:2017-10-06 16:26:59

标签: xaml xamarin.forms

我有一个使用App.xaml中的静态资源的ContentView。 app资源是自定义DataTemplateSelector

<c:ControlTemplateSelector  x:Key="controlTemplateSelector"
                    PickerWorkflowItemTemplate="{StaticResource pickerWorkflowItemTemplate}"
                    DatePickerWorkflowItemTemplate="{StaticResource datePickerWorkflowItemTemplate}"    
                    TimePickerWorkflowItemTemplate="{StaticResource timePickerWorkflowItemTemplate}"    
                    MultiPickerWorkflowItemTemplate ="{StaticResource multiPickerWorkflowItemTemplate}"                 
                    NumberPickerWorkflowItemTemplate ="{StaticResource numberPickerWorkflowItemTemplate}"
                    MultiPickerWithOptionWorkflowItemTemplate ="{StaticResource multiPickerWithOptionWorkflowItemTemplate}"
                    SwitchWorkflowItemTemplate ="{StaticResource switchWorkflowItemTemplate}"
                    GridWorkflowItemTemplate="{StaticResource gridWorkflowItemTemplate}"                        
                    TextBoxWorkflowItemTemplate="{StaticResource textBoxWorkflowItemTemplate}">

</c:ControlTemplateSelector>

我添加

<DataTemplate x:Key="horizontalStackContainerWorkflowItem">
        <c:HorizontalStackContainerWorkflowItem />
</DataTemplate>

到App.xaml中的ResourceDictionary我得到一个运行时异常:

  

Xamarin.Forms.Xaml.XamlParseException:超时gettingexception详细信息

消费观点:

  <?xml version="1.0" encoding="UTF-8"?>
    <ContentView xmlns="http://xamarin.com/schemas/2014/forms" 
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                 xmlns:controls="clr-namespace:XLabs.Forms.Controls;assembly=XLabs.Forms"
                 x:Class="Positron.Mobile.Controls.HorizontalStackContainerWorkflowItem"
                xmlns:vmc="clr-namespace:Positron.Mobile.ViewModel.Controls;assembly=Positron.Mobile"
                 x:Name="ContentView"
                xmlns:c="clr-namespace:Positron.Mobile.Controls;assembly=Positron.Mobile"
                 >

        <ContentView.Content>
            <ListView ItemTemplate="{StaticResource controlTemplateSelector}"  ItemsSource="{Binding ControlViewModels}" >
    ...

            </ListView>

        </ContentView.Content>
    </ContentView>

修改: 这似乎是抛出的实际异常。我只是不知道为什么我不能在我的数据模板中使用资源。

  

找不到关键controlTemplateSelector

的StaticResource

它似乎与以下问题Circular referenced IValueConverter in Application.Resources

非常相似

修改 以下工作但显然不是很好,因为您不希望在App.xaml资源字典中定义所有ContentView。所以仍然希望有人告诉我如何在没有这项工作的情况下完成它。

<DataTemplate x:Key="horizontalStackContainerWorkflowItemTemplate">
                <ContentView>
                    <ContentView.Content>
                        <ListView ItemTemplate="{StaticResource controlTemplateSelector}"  ItemsSource="{Binding ControlViewModels}" >
...

                        </ListView>
                    </ContentView.Content>
                </ContentView>
            </DataTemplate>
            <c:ControlTemplateSelector  x:Key="controlTemplateSelector"
                    PickerWorkflowItemTemplate="{StaticResource pickerWorkflowItemTemplate}"
                    DatePickerWorkflowItemTemplate="{StaticResource datePickerWorkflowItemTemplate}"    
                    TimePickerWorkflowItemTemplate="{StaticResource timePickerWorkflowItemTemplate}"    
                    MultiPickerWorkflowItemTemplate ="{StaticResource multiPickerWorkflowItemTemplate}"                 
                    NumberPickerWorkflowItemTemplate ="{StaticResource numberPickerWorkflowItemTemplate}"
                    MultiPickerWithOptionWorkflowItemTemplate ="{StaticResource multiPickerWithOptionWorkflowItemTemplate}"
                    SwitchWorkflowItemTemplate ="{StaticResource switchWorkflowItemTemplate}"
                    GridWorkflowItemTemplate="{StaticResource gridWorkflowItemTemplate}"                        
                    TextBoxWorkflowItemTemplate="{StaticResource textBoxWorkflowItemTemplate}"
                    HorizontalStackContainerWorkflowItemTemplate ="{StaticResource horizontalStackContainerWorkflowItemTemplate}">
            </c:ControlTemplateSelector>

0 个答案:

没有答案