【问题标题】:Xamarin forms ControlTemplate for header, another for footer and bindingsXamarin 为页眉形成 ControlTemplate,另一个用于页脚和绑定
【发布时间】:2018-06-10 14:46:35
【问题描述】:

我正在制作一个在每个屏幕上都有相同标题的应用程序,因此我为应用程序的该部分创建了一个 ControlTemplate,并在其上放置了一些按钮,这样就可以了。我很满意。

三个屏​​幕的页脚几乎相同,只是文本颜色和图像不同。我为页脚制作了​​另一个 ControlTemplate,我想根据当前显示的页面来操作带有绑定的图像上的 IsVisible 属性,但我不知道该怎么做。

我知道我需要编写一个转换器,我做到了,这似乎并不复杂,但我无法找到一种方法来实际绑定这些属性中的值。

两个 ControlTemplate 都是在应用程序级别定义的。

这是我如何使用它们的示例,也许这是错误的:

<ContentView ControlTemplate="{StaticResource Header}">
<!--This is the actuall page content-->
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="9*"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
    <!--Content of the page!-->
<Label Text="Welcome to Xamarin.Forms!" 
       VerticalOptions="Center" 
       HorizontalOptions="Center" 
       Grid.Row="0"/>
<!--Footer of the page!-->
    <ContentView ControlTemplate="{StaticResource BuySellPayFooter}"
                             Grid.Row="1"/>
    </Grid>
</ContentView>

我需要在页脚中绑定一些类的属性。怎么做?可以实现吗?

【问题讨论】:

    标签: xamarin binding xamarin.forms controltemplate controltemplates


    【解决方案1】:

    我使用 ControlTemplate 在每个页面上显示一个 ActivityIndi​​cator。

    对于指标的 IsVisible 属性,我将其与指标的 IsBusy 属性绑定 页面。

    这就是我在 ControlTemplate 的 XAML 中绑定它的方式:

    IsVisible="{TemplateBinding BindingContext.IsBusy}"
    

    如果我想改变每个页面上指示器的颜色,我可以为页面定义 BusyColor 属性并绑定它:

    Color="{TemplateBinding BindingContext.BusyColor}"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-05
      • 1970-01-01
      • 2017-08-12
      • 1970-01-01
      • 2014-07-07
      • 1970-01-01
      相关资源
      最近更新 更多