小编Dan*_*tin的帖子

Xamarin.Forms - 标签不居中

我有一个包含 2 个标签的 StackView。一种是普通文本,另一种是 FontAwesome Icon。

在此处输入图片说明

无论如何,两个标签都没有在 StackView 内垂直居中。这是他们的代码:

样式:

        <Style x:Key="FAIconedLabel" TargetType="Label">
            <Setter Property="TextColor" Value="White"/>
            <Setter Property="FontSize" Value="40" />
            <Setter Property="Margin" Value="0" />
        </Style>

        <Style x:Key="EmailLabel" TargetType="Label">
            <Setter Property="TextColor" Value="White"/>
            <Setter Property="FontSize" Value="20" />
        </Style>
Run Code Online (Sandbox Code Playgroud)

和视图本身

        <!-- Top Right -->
        <Grid BackgroundColor="{StaticResource LamaControlGray}"
              RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent,
                Property=Width,Factor=1,Constant=-400}"
              RelativeLayout.WidthConstraint="{ConstraintExpression
                Type=RelativeToParent,Property=Width,Factor=0,Constant=400}"
              RelativeLayout.HeightConstraint="{ConstraintExpression
                Type=RelativeToParent,Property=Height,Factor=0,Constant=40}" >
            <StackLayout Orientation="Horizontal" HorizontalOptions="End" VerticalOptions="FillAndExpand" BackgroundColor="Red">
                <Label x:Name="LblUserEmail" Margin="0,0,10,0" Text="{Binding UserEmail}" VerticalOptions="FillAndExpand" Style="{StaticResource EmailLabel}"/>
                <fal:FontAwesomeLabel Text="{Binding SettingsIcon}" BackgroundColor="Green" VerticalOptions="CenterAndExpand" Style="{StaticResource FAIconedLabel}" />
            </StackLayout>
        </Grid>
Run Code Online (Sandbox Code Playgroud)

我在这里想念什么吗?

编辑 1

我添加了一个 BackgroundColor …

stackview xamarin xamarin.forms

3
推荐指数
1
解决办法
5222
查看次数

Xamarin.Forms ScrollView 添加额外空间

我的 ScrollView 在我的 iPhone X 上的第一个孩子上方和最后一个孩子下方添加了额外的空间。这是图像上方的蓝色间隙。没有填充或边距。

在此处输入图片说明

我给了 ScrollView 一个蓝色背景以更好地查看它的尺寸。如果我删除 ScrollView,间距也消失了。这是我正在使用的代码

        <ScrollView>
            <!-- The MenuItems -->
            <Grid RowSpacing="0"
                  ColumnSpacing="0"
                  Margin="0, 0, 0, 0">
                <Grid.RowDefinitions>
                    <RowDefinition Height="200" />
                    <RowDefinition Height="20" />
                    <RowDefinition Height="350" />
                    <RowDefinition Height="300" />
                    <RowDefinition Height="300" />
                    <RowDefinition Height="300" />
                    <RowDefinition Height="300" />
                    <RowDefinition Height="200" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <!--<ColumnDefinition Width="*" /> -->
                </Grid.ColumnDefinitions>
<animatedViews:SavannahCanvasView HorizontalOptions="Center"
                                                  Grid.Row="0" />

                <Grid Grid.Row="2"
                      BackgroundColor="#fbc531">
                    <Image HeightRequest="100"
                           VerticalOptions="End"
                           HorizontalOptions="FillAndExpand"
                           Aspect="Fill"
                           Source="{imageExtensions:ImageResource Source=Cheetah.Forms.Assets.Images.Background_Torque.png, TheAssembly=Cheetah.Forms}" />

                    <StackLayout VerticalOptions="Center"
                                 HorizontalOptions="Center"
                                 Margin="0,-100,0,0">

                        <StackLayout.GestureRecognizers>
                            <TapGestureRecognizer Command="{Binding …
Run Code Online (Sandbox Code Playgroud)

c# xaml scrollview xamarin xamarin.forms

3
推荐指数
1
解决办法
2581
查看次数

Xamarin.Forms-视图高度等于宽度

我正在尝试将本机Xamarin.iOS转换为Xamarin.Forms,并遇到一个简单的布局问题。我想要实现的是一个类似红色网格的菜单:

良好的网格

因此,高度每Gridelement应该是相等宽度,但我得到的是这样的一种:

网格错误

我的Xaml看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>
<mvvm:BaseContentPage 
xmlns="http://xamarin.com/schemas/2014/forms" 
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:mvvm="clr-namespace:SharpLibrary.Forms.Source.MVVM;assembly=SharpLibrary.Forms"
xmlns:cc="clr-namespace:Gorilla.Forms.Source.UI.CustomControls"
x:Class="Gorilla.Forms.Source.UI.Guest.GuestMainPage">
<ContentPage.Content>
    <RelativeLayout
        VerticalOptions="FillAndExpand" 
        HorizontalOptions="FillAndExpand"
        >

        <Image Style="{StaticResource StandardBackgroundImage}" />
        <ScrollView 
            RelativeLayout.WidthConstraint = "{ConstraintExpression Type=RelativeToParent, Property=Width}"
            RelativeLayout.HeightConstraint = "{ConstraintExpression Type=RelativeToParent, Property=Height}" 
            >
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="auto" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>

                <cc:GridMenuItem
                    x:Name="testBox"
                    Grid.Row="0" Grid.Column="0" 
                    BackgroundColor="Red"
                    Title="Test" 
                    Icon="Text" />
                <Frame 
                    x:Name="testFrame" 
                    Grid.Row="0" Grid.Column="1" 
                    BackgroundColor="Gray"
                    HeightRequest="{Binding WidthRequest}">
                        <Label Text="gdjfgzhg" />
                </Frame>
            </Grid>
        </ScrollView>
    </RelativeLayout>
</ContentPage.Content>
</mvvm:BaseContentPage>
Run Code Online (Sandbox Code Playgroud)

我无法弄清楚我做错了什么,我还发现了一些线程,人们希望实现与我相同的目的,但并没有达到我的期望。 …

c# xamarin.ios xamarin.forms

2
推荐指数
1
解决办法
1540
查看次数

flutter http post“类型‘int’不是类型转换中类型‘String’的子类型”

我正在尝试将一些数据发布到此结构的后端:

class Activity {
  String id;
  String employeeId;
  String locationId;
  String locationName;
  DateTime startDateTime;
  DateTime endDateTime;
  int breakMinutes;
  String actionId;
  String actionType;
  int startDeviceType;
  int endDeviceType;
  String comment;

  factory Activity.fromJson(Map<String, dynamic> json) =>
      _$ActivityFromJson(json);
  Map<String, dynamic> toJson() => _$ActivityToJson(this);
}
Run Code Online (Sandbox Code Playgroud)

我正在将类转换为 Map,如下所示:

Map<String, dynamic> _$ActivityToJson(Activity instance) => <String, dynamic>{
      'id': instance.id,
      'employeeId': instance.employeeId,
      'locationId': instance.locationId,
      'locationName': instance.locationName,
      'startDateTime': instance.startDateTime?.toIso8601String(),
      'endDateTime': instance.endDateTime?.toIso8601String(),
      'breakMinutes': instance.breakMinutes,
      'actionId': instance.actionId,
      'actionType': instance.actionType,
      'startDeviceType': instance.startDeviceType,
      'endDeviceType': instance.endDeviceType,
      'comment': instance.comment,
    };
Run Code Online (Sandbox Code Playgroud)

...并用以下几行发送:

Future<HttpError> updateAsync(Activity activity) async { …
Run Code Online (Sandbox Code Playgroud)

rest post http dart flutter

2
推荐指数
1
解决办法
2699
查看次数

C# 使用静态方法扩展 String 类

我想知道是否有一种方法可以使用名为GenerateRandom() 的方法来扩展字符串类,该方法会生成随机字符串。也许这看起来像

string.CreateRandom();
Run Code Online (Sandbox Code Playgroud)

正如我所读到的,除了创建字符串实例然后调用扩展方法之外,没有其他办法。也许有一个,而且你知道。

感谢您的帮助!

c# extension-methods

1
推荐指数
1
解决办法
8164
查看次数

通用类型作为参数,必须实现特定接口

我有一个方法,我想重新创建更通用的方法。

public Task<bool> DoSomething<T>(T t) where T : Type, IAnyInterface
Run Code Online (Sandbox Code Playgroud)

如您所见,我想要一个Type作为参数,它必须实现IAnyInterface

但如果我调用该方法,

DoSomething(typeof(ObjectThatImplementsIAnyInterface));
Run Code Online (Sandbox Code Playgroud)

我收到错误:

类型“System.Type”不能用作泛型类型或方法“DoSomething(...)”中的类型参数“T” 没有从“System.Type”到“IAnyInterface”的隐式转换

那么我怎样才能让该方法接受该类型呢?

c# generics interface

1
推荐指数
1
解决办法
385
查看次数

附加到进程 IIS 未命中断点

当我将 Visual Studio 附加到我在 IIS 中运行的 Asp.Core MVC 应用程序时,断点不会被命中。我检查了放置文件的 IIS 文件夹,里面有需要的 .pdb 文件。这些文件是通过 VS 中的发布命令创建的。

在此处输入图片说明

我不知道你需要我在这里分享什么,所以对这些信息感到抱歉。

c# iis asp.net-mvc

1
推荐指数
2
解决办法
5493
查看次数