如何在框架内填充和展开按钮 Xamarin.Forms
How to fill and expand a Button within a Frame Xamarin.Forms
我有不同的按钮要放在 <Frame>
控件中,所有这些都是为了避免图像在 <ListView>
中溢出,但是当放置 HorizontalOptions 和 VerticalOptions 时属性 在 FillAndExpand 中没有填充 Frame,我附上了问题的图片
如何让<Frame>
里面的<Button>
填满space?我试图为列和行设置自动 属性 但我没有成功。
如何保持按钮的大小(高度和宽度)而不丢失框架?
如何填充和展开框架内的按钮?
对我有什么帮助吗?
VIEW.XAML:
<ListView
ItemsSource="{Binding ListaInventario}"
SelectionMode="None"
VerticalOptions="FillAndExpand"
IsRefreshing="{Binding IsRefreshing, Mode=TwoWay}"
HasUnevenRows="True">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout
Margin="0,4,0,0"
Orientation="Vertical">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="5*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Label
Text="{Binding Id}"
FontSize="Small"
HorizontalOptions="Center"
FontAttributes="Bold"
HeightRequest="39"
VerticalTextAlignment="Start"
TextColor="{StaticResource das.color.texto}"
Grid.Column="0"
Grid.Row="0">
</Label>
<Label
Text="{Binding NombreComercial}"
HorizontalOptions="Start"
FontSize="Small"
MaxLines="3"
HeightRequest="39"
TextColor="{StaticResource das.color.texto}"
VerticalOptions="Start"
Grid.Column="1"
Grid.Row="0">
</Label>
<Frame
HorizontalOptions="End"
BackgroundColor="Transparent"
Grid.Column="2"
Grid.Row="0">
<Button
ImageSource="ic_pdf"
HeightRequest="35"
WidthRequest="50"
BackgroundColor="{StaticResource das.color.estado_primary}"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
Command="{Binding HDSSisquimCommand}"/>
</Frame>
</Grid>
<!---->
<!--CANTIDAD-->
<StackLayout
Orientation="Horizontal"
HorizontalOptions="FillAndExpand"
Margin="0,1,0,2">
<StackLayout
Orientation="Horizontal"
HorizontalOptions="Start"
Margin="0,0,3,0">
<Label
HorizontalOptions="Start"
HorizontalTextAlignment="Start"
VerticalOptions="End"
VerticalTextAlignment="Center"
Text="Cantidad: "
FontAttributes="Bold"
FontSize="Small"
HeightRequest="35"
IsEnabled="{Binding EnabledEstimadoEntry}"></Label>
<Entry
HorizontalOptions="FillAndExpand"
Placeholder="Cantidad"
Keyboard="Numeric"
HorizontalTextAlignment="Center"
MaxLength="4"
FontSize="Small"
HeightRequest="35"
Text="{Binding CantidadDecimal}"
IsEnabled="{Binding EnabledContenedorEntry}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStatesEntry">
<VisualState x:Name="Normal">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="Transparent" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Focused">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="LightGray" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Entry>
</StackLayout>
<!--UNIDAD-->
<StackLayout
Orientation="Horizontal"
HorizontalOptions="FillAndExpand">
<Label
HorizontalOptions="Start"
HorizontalTextAlignment="Start"
VerticalOptions="End"
VerticalTextAlignment="Center"
Text="Unidad: "
FontAttributes="Bold"
FontSize="Small"
HeightRequest="35"
IsEnabled="{Binding EnabledEstimadoEntry}"></Label>
<Picker
iOSSpecific:Picker.UpdateMode = "WhenFinished"
ItemsSource="{Binding ListaUnidadesMedida}"
SelectedItem="{Binding SelectedUnidadMedida}"
ItemDisplayBinding="{Binding NombreCorto}"
Title="Unidad"
FontSize="Small"
HeightRequest="35"
HorizontalOptions="FillAndExpand"
IsEnabled="{Binding EnabledContenedor}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStatesPicker">
<VisualState x:Name="Normal">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="Transparent" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Focused">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="LightGray" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Picker>
</StackLayout>
</StackLayout>
<!-- TWO BUTTONS -->
<StackLayout
Orientation="Horizontal"
HorizontalOptions="End"
Margin="0,1,0,2">
<Button
Margin="0,0,2,0"
ImageSource="ic_actualizar"
BackgroundColor="{Binding ColorBotonActualizar}"
HorizontalOptions="End"
VerticalOptions="Center"
HeightRequest="35"
WidthRequest="50"
Command="{Binding ActualizarSQCommand}"/>
<Button
ImageSource="ic_minus_sisquim"
BackgroundColor="{StaticResource das.color.estado_danger}"
HorizontalOptions="End"
VerticalOptions="Center"
HeightRequest="35"
WidthRequest="50"
Command="{Binding DesasociarSQCommand}"/>
</StackLayout>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
您可以尝试在 Frame
中添加 属性 Padding="0"
并删除 Button
.
的以下属性
HeightRequest="35"
WidthRequest="50"
所以代码是这样的:
<Frame
HorizontalOptions="End"
BackgroundColor="Green"
Grid.Column="2"
Padding="0"
Grid.Row="0">
<Button
Text="test"
BackgroundColor="Accent"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
/>
</Frame>
我只需要在框架中设置Padding="0"
。
HorizontalOptions
和 VerticalOptions
不需要按照 @Jessie Zhang -MSFT
的建议设置。
<Frame Padding="0">
<Button />
</Frame>
我有不同的按钮要放在 <Frame>
控件中,所有这些都是为了避免图像在 <ListView>
中溢出,但是当放置 HorizontalOptions 和 VerticalOptions 时属性 在 FillAndExpand 中没有填充 Frame,我附上了问题的图片
如何让<Frame>
里面的<Button>
填满space?我试图为列和行设置自动 属性 但我没有成功。
如何保持按钮的大小(高度和宽度)而不丢失框架? 如何填充和展开框架内的按钮?
对我有什么帮助吗?
VIEW.XAML:
<ListView
ItemsSource="{Binding ListaInventario}"
SelectionMode="None"
VerticalOptions="FillAndExpand"
IsRefreshing="{Binding IsRefreshing, Mode=TwoWay}"
HasUnevenRows="True">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout
Margin="0,4,0,0"
Orientation="Vertical">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*" />
<ColumnDefinition Width="5*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Label
Text="{Binding Id}"
FontSize="Small"
HorizontalOptions="Center"
FontAttributes="Bold"
HeightRequest="39"
VerticalTextAlignment="Start"
TextColor="{StaticResource das.color.texto}"
Grid.Column="0"
Grid.Row="0">
</Label>
<Label
Text="{Binding NombreComercial}"
HorizontalOptions="Start"
FontSize="Small"
MaxLines="3"
HeightRequest="39"
TextColor="{StaticResource das.color.texto}"
VerticalOptions="Start"
Grid.Column="1"
Grid.Row="0">
</Label>
<Frame
HorizontalOptions="End"
BackgroundColor="Transparent"
Grid.Column="2"
Grid.Row="0">
<Button
ImageSource="ic_pdf"
HeightRequest="35"
WidthRequest="50"
BackgroundColor="{StaticResource das.color.estado_primary}"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
Command="{Binding HDSSisquimCommand}"/>
</Frame>
</Grid>
<!---->
<!--CANTIDAD-->
<StackLayout
Orientation="Horizontal"
HorizontalOptions="FillAndExpand"
Margin="0,1,0,2">
<StackLayout
Orientation="Horizontal"
HorizontalOptions="Start"
Margin="0,0,3,0">
<Label
HorizontalOptions="Start"
HorizontalTextAlignment="Start"
VerticalOptions="End"
VerticalTextAlignment="Center"
Text="Cantidad: "
FontAttributes="Bold"
FontSize="Small"
HeightRequest="35"
IsEnabled="{Binding EnabledEstimadoEntry}"></Label>
<Entry
HorizontalOptions="FillAndExpand"
Placeholder="Cantidad"
Keyboard="Numeric"
HorizontalTextAlignment="Center"
MaxLength="4"
FontSize="Small"
HeightRequest="35"
Text="{Binding CantidadDecimal}"
IsEnabled="{Binding EnabledContenedorEntry}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStatesEntry">
<VisualState x:Name="Normal">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="Transparent" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Focused">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="LightGray" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Entry>
</StackLayout>
<!--UNIDAD-->
<StackLayout
Orientation="Horizontal"
HorizontalOptions="FillAndExpand">
<Label
HorizontalOptions="Start"
HorizontalTextAlignment="Start"
VerticalOptions="End"
VerticalTextAlignment="Center"
Text="Unidad: "
FontAttributes="Bold"
FontSize="Small"
HeightRequest="35"
IsEnabled="{Binding EnabledEstimadoEntry}"></Label>
<Picker
iOSSpecific:Picker.UpdateMode = "WhenFinished"
ItemsSource="{Binding ListaUnidadesMedida}"
SelectedItem="{Binding SelectedUnidadMedida}"
ItemDisplayBinding="{Binding NombreCorto}"
Title="Unidad"
FontSize="Small"
HeightRequest="35"
HorizontalOptions="FillAndExpand"
IsEnabled="{Binding EnabledContenedor}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStatesPicker">
<VisualState x:Name="Normal">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="Transparent" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Focused">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="LightGray" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Picker>
</StackLayout>
</StackLayout>
<!-- TWO BUTTONS -->
<StackLayout
Orientation="Horizontal"
HorizontalOptions="End"
Margin="0,1,0,2">
<Button
Margin="0,0,2,0"
ImageSource="ic_actualizar"
BackgroundColor="{Binding ColorBotonActualizar}"
HorizontalOptions="End"
VerticalOptions="Center"
HeightRequest="35"
WidthRequest="50"
Command="{Binding ActualizarSQCommand}"/>
<Button
ImageSource="ic_minus_sisquim"
BackgroundColor="{StaticResource das.color.estado_danger}"
HorizontalOptions="End"
VerticalOptions="Center"
HeightRequest="35"
WidthRequest="50"
Command="{Binding DesasociarSQCommand}"/>
</StackLayout>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
您可以尝试在 Frame
中添加 属性 Padding="0"
并删除 Button
.
HeightRequest="35"
WidthRequest="50"
所以代码是这样的:
<Frame
HorizontalOptions="End"
BackgroundColor="Green"
Grid.Column="2"
Padding="0"
Grid.Row="0">
<Button
Text="test"
BackgroundColor="Accent"
HorizontalOptions="FillAndExpand"
VerticalOptions="FillAndExpand"
/>
</Frame>
我只需要在框架中设置Padding="0"
。
HorizontalOptions
和 VerticalOptions
不需要按照 @Jessie Zhang -MSFT
的建议设置。
<Frame Padding="0">
<Button />
</Frame>