我在Xamarin Forms中有一个简单的条目:
<Entry Text="{Binding Number, Mode=TwoWay}" Placeholder="Number" Keyboard="Numeric" />
Run Code Online (Sandbox Code Playgroud)
在ViewModel中有属性:
private int? _number;
public int? Number
{
get { return _number; }
set
{
if (SetProperty(ref _number, value))
{
OnPropertyChange(nameof(Number));
}
}
}
Run Code Online (Sandbox Code Playgroud)
我在Entry中输入数字并按下按钮,但是在按钮单击过程中 - 数字仍为空.我究竟做错了什么?
在App.xaml我有这个代码:
<Application.Resources>
<ResourceDictionary>
<Color x:Key="Yellow">#ffd966</Color>
</ResourceDictionary>
</Application.Resources>
Run Code Online (Sandbox Code Playgroud)
在C#中我有这个代码:
public Color BackgroundColor
{
get { return IsSelected ? Color.Yellow : Color.White; }
}
Run Code Online (Sandbox Code Playgroud)
我想用App.xaml中的颜色改变Color.Yellow.如何从C#中的App.xaml引用颜色?
我按照本教程创建了下划线效果.但是,当我的页面启动时,它会被捕获,无一例外.有没有人设法创建下划线效果?这是一个代码:
UnderlineEffect.cs:
namespace XX.CustomForms
{
public class UnderlineEffect : RoutingEffect
{
public const string EffectNamespace = "XX.CustomForms";
public UnderlineEffect() : base($"{EffectNamespace}.{nameof(UnderlineEffect)}")
{
}
}
}
Run Code Online (Sandbox Code Playgroud)
UnderlineLabel_Droid.cs:
[assembly: ResolutionGroupName(UnderlineEffect.EffectNamespace)]
[assembly: ExportEffect(typeof(UnderlineEffect), nameof(UnderlineEffect))]
namespace XX.Droid.Renderers
{
public class UnderlineEffect : PlatformEffect
{
protected override void OnAttached()
{
SetUnderline(true);
}
protected override void OnDetached()
{
SetUnderline(false);
}
protected override void OnElementPropertyChanged(System.ComponentModel.PropertyChangedEventArgs args)
{
base.OnElementPropertyChanged(args);
if (args.PropertyName == Label.TextProperty.PropertyName || args.PropertyName == Label.FormattedTextProperty.PropertyName)
{
SetUnderline(true);
}
}
private void SetUnderline(bool underlined)
{ …
Run Code Online (Sandbox Code Playgroud) 我在Xamarin Forms应用程序中使用Rg插件弹出窗口进行弹出。我想禁止用户关闭此弹出窗口。一段时间后,应用程序将关闭此弹出窗口。可能吗?
为什么我需要这样做:当用户第一次打开应用程序时,我想显示通常的开始页面,并在其顶部弹出。两者都可见:中间有一个弹出窗口,其周围是通常的起始页面,带有灰色覆盖。从服务器中获取数据时,将在弹出窗口中显示进度条。用户应该无法关闭此弹出窗口。提取数据结束后,我想刷新起始页面并关闭此模式。
我在Visual Studio 2017中有.NET Core 2项目.我正在尝试添加(Postgresql)数据库连接.这是一个代码:
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext(options =>
options.UseNpgsql(Configuration.GetConnectionString("DefaultConnection")));
// Add framework services.
services.AddMvc();
}
Run Code Online (Sandbox Code Playgroud)
但编译器抱怨这条消息:
IServiceCollection不包含'AddDbContext'的定义,并且没有可以找到接受类型'IServiceCollection'的第一个参数的扩展方法'AddDbContext'(你是否缺少using指令或汇编引用?)
我安装了NuGet包Npgsql.我也尝试安装NuGet包EntityFramework,但我收到错误:
包恢复失败.回滚"MyProject"的包更改.
这是我问题的根源吗?我应该安装一些其他库吗?
在这个问题上使用了 AddEntityFramework()和AddEntityFrameworkNpgsql()程序,但是我的项目中的编译器也无法识别这两个程序.
我有Xamarin Forms解决方案,并且在iOS项目中,我想将Stream中的图像转换为UIImage。我通过以下代码获得了Stream:
var _captureSession = new AVCaptureSession();
var _captureDevice = AVCaptureDevice.GetDefaultDevice(AVMediaType.Video);
var output = new AVCaptureStillImageOutput { OutputSettings = new NSDictionary(AVVideo.CodecKey, AVVideo.CodecJPEG) };
NSError error;
_captureSession.AddInput(new AVCaptureDeviceInput(_captureDevice, out error));
_captureSession.AddOutput(output);
_captureSession.StartRunning();
var buffer = await output.CaptureStillImageTaskAsync(output.Connections[0]);
NSData data = AVCaptureStillImageOutput.JpegStillToNSData(buffer);
Stream stream = data.AsStream();
Run Code Online (Sandbox Code Playgroud)
我需要UIImage以便使用以下代码旋转它:
public UIImage RotateImage(UIImage image)
{
CGImage imgRef = image.CGImage;
float width = imgRef.Width;
float height = imgRef.Height;
CGAffineTransform transform = CGAffineTransform.MakeIdentity();
RectangleF bounds = new RectangleF(0, 0, width, height);
float scaleRatio = bounds.Size.Width / width; …
Run Code Online (Sandbox Code Playgroud) 我有带有.NET Core 2项目的VS 2017。如何打开project.json?它未在解决方案资源管理器中列出。我可以找到appsettings.json,但找不到project.json。我是否应该通过右键单击项目并选择一些设置来打开它?
我有Xamarin Forms解决方案,在一个页面上有图像列表.单击图像时,我想触发具有图像路径作为参数的程序.在xaml我定义图像:
<Image Source="{Binding ImagePath}"
WidthRequest="30" HeightRequest="30"
HorizontalOptions="CenterAndExpand" VerticalOptions="CenterAndExpand" >
<Image.GestureRecognizers>
<TapGestureRecognizer Command="{Binding TapImageCommand}" CommandParameter="{Binding ImagePath}" />
</Image.GestureRecognizers>
</Image>
Run Code Online (Sandbox Code Playgroud)
和TapImageCommand在视图模型的构造函数中定义为:
TapImageCommand = new Command<string>(ImagePath =>
{
OnImageTapped(ImagePath);
});
Run Code Online (Sandbox Code Playgroud)
和TapImageCommand定义为:
public ICommand TapImageCommand { get; set; }
Run Code Online (Sandbox Code Playgroud)
问题是永远不会触发OnImageTapped.我究竟做错了什么?
我有Xamarin Forms应用程序。我的页面底部应如下所示:
当前看起来像这样:
问题是StackLayout不会扩展为填充空间。这是我的xaml:
<StackLayout Orientation="Horizontal" HorizontalOptions="FillAndExpand" VerticalOptions="End" Spacing="0" >
<Grid ColumnSpacing="0" RowSpacing="0" HorizontalOptions="FillAndExpand">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="40" />
</Grid.RowDefinitions>
<StackLayout HorizontalOptions="CenterAndExpand" Grid.Column="0" Grid.Row="1" BackgroundColor="Blue" >
<Label Text="First" TextColor="#FFFFFF" HorizontalOptions="CenterAndExpand" />
</StackLayout>
<StackLayout HorizontalOptions="CenterAndExpand" Grid.Column="1" Grid.Row="1" BackgroundColor="Red" >
<Label Text="Second" TextColor="#FFFFFF" HorizontalOptions="CenterAndExpand" />
</StackLayout>
</Grid>
</StackLayout>
Run Code Online (Sandbox Code Playgroud)
如何在Grid中扩展StackLayout?我希望中间有蓝色和红色背景。
我有Xamarin Forms项目,在我的页面上有以下代码:
<Image Source="genea_login_logo.png">
<Image.GestureRecognizers>
<TapGestureRecognizer Command="{Binding LogoCommand}" NumberOfTapsRequired="2" />
</Image.GestureRecognizers>
</Image>
Run Code Online (Sandbox Code Playgroud)
它按预期工作。但是,当我将NumberOfTapsRequired从2更改为5时,它将不再起作用。这是预期的行为吗?是否可以实现5单击命令?
编辑:这仅在Android上。