简体   繁体   English

如何在另一个内部调用 xaml

[英]How can I call a xaml inside another

I have a screen as main and a secondary with two buttons(ImageButton) and I would like to call the screen with the buttons(ImageButton) inside the main.我有一个主屏幕和一个带有两个按钮(ImageButton)的辅助屏幕,我想用主屏幕内的按钮(ImageButton)调用屏幕。 As there were several screens with the same buttons(ImageButton) to decrease the amount of image in each screen I want to call this xaml with buttons(ImageButton) inside the other screens to simplify the amount of image.由于有几个屏幕具有相同的按钮(ImageButton)来减少每个屏幕中的图像数量,我想在其他屏幕内使用按钮(ImageButton)调用此 xaml 以简化图像数量。 I tried this way and it did not work.我试过这种方式,但没有奏效。

Main主要的

 <StackLayout>
        <!-- Place new controls here -->
        <Label Text="Welcome to Xamarin.Forms!" 
           HorizontalOptions="Center"
           VerticalOptions="CenterAndExpand" />
    </StackLayout>
    <ContentPage.Content>
        <local:tela></local:tela>
    </ContentPage.Content>

Tela特拉

<ContentPage.Content>
        <StackLayout HorizontalOptions="EndAndExpand" Orientation="Horizontal">
            <Button Text="Abrir"></Button>
            <Button Text="Fechar"></Button>
        </StackLayout>
    </ContentPage.Content>

Your file Tela should be ContentView instead of ContentPage .您的文件Tela应该是ContentView而不是ContentPage

<ContentPage.Content>
<StackLayout>
    <StackLayout>
        <!-- Place new controls here -->
        <Label Text="Welcome to Xamarin.Forms!" 
      HorizontalOptions="Center"
   VerticalOptions="CenterAndExpand" />
    </StackLayout>
    <local:tela></local:tela>
</StackLayout>
</ContentPage.Content>

Your ContentView你的内容ContentView

<ContentView xmlns="http://xamarin.com/schemas/2014/forms" 
     xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
     x:Class="App1.Tela">

<StackLayout HorizontalOptions="EndAndExpand" Orientation="Horizontal">
    <Button Text="Abrir"></Button>
    <Button Text="Fechar"></Button>
</StackLayout>

</ContentView>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从另一个 xaml 调用 x:Name - How can I call the x:Name from another xaml 如何将ViewModel绑定到另一个XAML文件的ListView中的XAML文件? - How can I bind a ViewModel to an XAML file inside a ListView of another XAML file? 如何在xaml页面中调用构造函数? - How can I call a constructor in my xaml page? 如何将 xaml 属性绑定到另一个类中的静态变量? - How can I bind a xaml property to a static variable in another class? UWP:如何从另一个 XAML 更改 UI? - UWP : how can I change UI from another XAML? 如何在 Silverlight XAML 中引用另一个名称空间中的绑定转换器? - How can I refer to a binding converter in another namespace in Silverlight XAML? XamarinForms XAML:如何从另一个XAML文件(如ResourceDictionaries)继承属性? - XamarinForms XAML: How can I inherit properties from another XAML file like ResourceDictionaries? 我可以通过DataTrigger(XAML)调用函数吗? - Can i call a function via DataTrigger (XAML)? 我可以用XAML中的另一个控件替换一个控件吗 - Can I replace a control with another control in XAML 如何在没有停止的情况下在另一个异步方法中创建调用异步方法 - How can I create call an async method inside another async method without it stalling
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM