c# - Xamarin:在代码隐藏中更改 GridItemLayout 的值
问题描述
<CollectionView Grid.Row="2" Grid.Column="0" x:Name="collectionViewItemsLayout" ItemsSource="{Binding BaseCustomersCards}" ItemTemplate="{StaticResource CustomerCardTemplateSelector}" >
<CollectionView.ItemsLayout>
<GridItemsLayout Orientation="Vertical" Span="5" />
</CollectionView.ItemsLayout>
</CollectionView>
我有这个collectionview,但正在尝试更改手机平板电脑的跨度。默认值为 5,但电话值应为 3。
var idiom = DeviceInfo.Idiom;
if (idiom == DeviceIdiom.Phone)
{
collectionViewItemsLayout.SetValue(GridItemsLayout.SpanProperty, 3);
}
我在代码隐藏中进行了更改以更改它,该方法触发但不会更改任何内容。我试图将 3 作为字符串和纯值。我也尝试将 x:name 放在属性中,但它不能去那里。
解决方案
通过创建一个新的 GridItem 并设置它来工作
if (idiom == DeviceIdiom.Phone)
{
var grid = new GridItemsLayout(ItemsLayoutOrientation.Vertical)
{
Span = 3,
};
collectionViewItemsLayout.SetValue(CollectionView.ItemsLayoutProperty, grid);
}
推荐阅读
- c++ - 时间:2019-05-10 标签:c++vector
实施问题 - batch-file - 如何使用 cmd.exe 批处理文件(for 循环)将 JSON 语法转换为另一种语法
- javascript - TypeError:food.map 不是 Reactjs 中的函数
- c# - EF core gives error after adding a function inside "Where" lambda expression [EF-CORE 3.1]
- javascript - export html to PDF in JSPDF
- sql - Masking ID and Name in SQL
- android - Google Play Internal Testing App Rejected
- powershell - PowerShell - get-hotfix on multiple servers - error handling
- unity3d - Unity Rig 重量不会通过动画剪辑立即更新
- elasticsearch - 如何在无痛脚本中深度克隆对象字段