【问题标题】:Is it possible to bind RelativeLayout constraints?是否可以绑定 RelativeLayout 约束?
【发布时间】:2017-02-27 04:12:32
【问题描述】:

我正在使用以下 XAML 代码在 ListView 中呈现一些数据:

<ListView x:Name="myListView"
          ItemsSource="{Binding myData}"
          RowHeight="230">
    <ListView.ItemTemplate>
      <DataTemplate>
        <ViewCell>
          <ViewCell.View>
            <RelativeLayout Padding="1">
              <StackLayout x:Name="stackLayoutTitle"
                           Padding="5" 
                           Orientation="Vertical" 
                           VerticalOptions="EndAndExpand"
                           RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent, Property=Width}"
                           RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor=0.6}">
                <Label Text="{Binding myText}"
                       FontSize="Medium"
                       FontAttributes="Bold"
                       TextColor="Black">
                </Label>
              </StackLayout>
            </RelativeLayout>
          </ViewCell.View>
        </ViewCell>
      </DataTemplate>
    </ListView.ItemTemplate>
  </ListView>

数据渲染正常。现在,我想做的是对 RelativeYConstranit 的 Factor 属性使用条带,以根据一些计算定位相应的 StackLayout。像这样 (请参阅 Factor 属性):

RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent, Property=Height, Factor={Binding someValue}}"

但是,运行应用程序时出现错误。

有谁知道是否可以为此使用绑定表达式?

谢谢。

【问题讨论】:

    标签: xaml xamarin.forms xamarin.forms.listview


    【解决方案1】:

    我有这个问题。 “因子”不是 BindingProperty。因此现在是不可能的。

    【讨论】:

      【解决方案2】:

      我尝试了类似的事情,但未能为 YConstraint 绑定因子,这里解释了为什么它不起作用

      来自文档:

      在 C# 中,相对约束被定义为函数。因子之类的概念不存在,但可以手动实现。

      我得到的错误信息:

      无法分配属性“因子”:属性不存在,或者不可分配,或者值和属性之间的类型不匹配

      结论: 没有可绑定的属性(注意它必须是可绑定的属性,否则无法绑定)底层代码中的因素,因此无法绑定。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-07-08
        • 2019-09-28
        • 2021-11-02
        • 1970-01-01
        • 1970-01-01
        • 2016-07-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多