C#转换为Xaml

时间:2018-11-08 11:16:30

标签: c# xaml xamarin xamarin.forms

我想实现一个自定义手风琴ui元素,但是代码已经用C#(https://github.com/Kimserey/AccordionView)编写,但是我想使用xaml。我试图在内容中添加手风琴视图,但是在编译时出现以下错误

HomePage.xaml:错误:字典中不存在给定的键。

这是我的xaml代码

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:customaccordionmenu="clr-namespace:CustomAccordionMenu"
             x:Class="CustomAccordionMenu.HomePage" Title="Accordion Example" >
    <ContentPage.Content>
        <StackLayout VerticalOptions = "Center">            
            <customaccordionmenu:AccordionView/>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

所以我只想创建一个手风琴视图并将内容添加到xaml中,而不是c#中

PS:该项目适用于Xamarin.Forms

1 个答案:

答案 0 :(得分:0)

您正在尝试实例化一个空的AccordionView。从github中的代码来看,手风琴视图没有无参数构造函数,这可能会引起问题。

AccordionSectionView类调用

private ImageSource _arrowRight = ImageSource.FromFile("ic_keyboard_arrow_right_white_24dp.png");

以及

private ImageSource _arrowDown = ImageSource.FromFile("ic_keyboard_arrow_down_white_24dp.png");

因此,如果这些文件不在您应用的资源中,并且以相同的方式命名,这也可能是导致崩溃的原因。