首页 文章

是否可以绑定RelativeLayout约束?

提问于
浏览
2

我使用以下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>

数据呈现正常 . 现在,我想要做的是使用banding作为RelativeYConstranit的Factor属性,根据一些计算来定位相应的StackLayout . 像这样的东西 (see the Factor property):

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

但是,当运行应用程序时,我收到一个错误 .

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

谢谢 .

2 回答

  • 0

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

  • 0

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

    从文档:

    在C#中,相对约束被定义为函数 . 像Factor这样的概念不存在,但可以手动实现 .

    我收到的错误消息:

    不能赋予属性“因子”:属性不存在,或者不可赋值,或者值与属性之间不匹配的类型

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

相关问题