xaml - 如何在框架内使用网格分隔条目和图像?
问题描述
我正在制作一个右边Entry
有一个。Image
我遇到的问题是文本放在后面Image
,我想要做的是文本在到达时被切断Image
,将条目与Image
. 我正在使用 aFrame
和在它里面, a Grid
。我试图将右边距添加到Entry
但Image
正在滚动。我Entry
正在使用 NuGet:Xamarin.Forms.Visual.Material
这是我的代码:
<StackLayout>
<Frame BackgroundColor="Transparent" HasShadow="False">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Entry
x:Name="entrycontrol"
BackgroundColor="{Binding Source={x:Reference ValidateView}, Path=BGColor}"
HeightRequest="60"
Visual="Material"
WidthRequest="{Binding Source={x:Reference ValidateView}, Path=Width}" />
<Image
x:Name="ImageRight"
Grid.Column="0"
Margin="0,0,5,0"
HeightRequest="25"
HorizontalOptions="End" />
</Grid>
</Frame>
</StackLayout>
我在后面的代码Source
中Image
建立它。
解决方案
您的主要问题是您将您的控件覆盖Image
在控件之上Entry
。您需要指定 aGrid.Column="1"
以便它使用右侧列。Grid
可以在 Microsoft 网站上找到有关布局如何工作的详细说明
我建议您不需要绑定控件的WidthRequest
属性Entry
。另外,我会交换您的列定义。Auto
表示该列的大小将增长,*
这意味着它将根据已定义的其他列的大小拉伸到一个大小。
总结一下你想要的东西:
<StackLayout>
<Frame BackgroundColor="Transparent" HasShadow="False">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" /> <!-- swapped -->
<ColumnDefinition Width="Auto" /> <!-- swapped -->
</Grid.ColumnDefinitions>
<Entry x:Name="entrycontrol"
BackgroundColor="{Binding Source={x:Reference ValidateView}, Path=BGColor}"
HeightRequest="60"
Visual="Material" />
<Image x:Name="ImageRight"
Grid.Column="1"
Margin="0,0,5,0"
HeightRequest="25"
HorizontalOptions="End" />
</Grid>
</Frame>
</StackLayout>
更好的是,如果你有一个固定的图像尺寸,那么你可以简单地设置你ColumnDefinition
的尺寸。
推荐阅读
- python - Python中如何确定范围
- reactjs - Next.js API 路由在不发送响应的情况下解析
- c++ - 带有winsock的交互式终端
- gitlab - 我们在哪里提到 .gitlab-ci.yml 中的 gitlab-runner 执行器?
- data-structures - Categorize Key-Value Pairs/HashMap的HashMap的替代品
- python - 为什么在 emacs 中 lsp-mode 提示“路径上不存在命令 pyls”?
- python - 如何注释由 2 个不同数组组成的条形图?
- python-3.x - 当frozenset用作新frozenset的迭代时,如何重现frozenset的行为?
- flutter - Flutter 相机手电筒一直亮着
- python - 在计算混淆矩阵时获取样本数量不一致的输入变量的错误