小编Kri*_*ten的帖子

如何在Xaml文件中的Xamarin.Forms中添加Checkbox?

我是xamarin.forms的新手,我需要添加一个复选框,单选按钮和下拉列表.我从网上尝试了一些样本,但我无法获得复选框.任何人都可以帮助我在xamarin.forms中实现这一目标吗?

Xaml文件

<toolkit:CheckBox Text ="Employee"
                  FontSize="20"
                  CheckedChanged ="OnClicked"/>
Run Code Online (Sandbox Code Playgroud)

要么

<controls:CheckBox DefaultText="Default text"
                               HorizontalOptions="FillAndExpand"
                               TextColor="Green"
                               FontSize="25"
                               FontName="AmericanTypewriter"/>
Run Code Online (Sandbox Code Playgroud)

一些链接或示例代码将使其更容易理解.

c# checkbox xaml xamarin.ios

10
推荐指数
2
解决办法
3万
查看次数

Windows 8 WrapPanel

我有自动将StackPanel分解为下一行的问题.这是示例代码:

<StackPanel Orientation="Horizontal" Width="180">
   <TextBlock.../>
   <TextBlock.../>
   <TextBlock.../>
   <Image.../>
    ...
</StackPanel>
Run Code Online (Sandbox Code Playgroud)

现在我想要达到这样的效果:当StackPanel中没有足够的空间用于另一个元素时,它应该放在新行中.我怎么能得到这个(没有必要使用stackpanel)?

PS:我的目标是将文本和图像放在一行中(当没有足够的空间用于另一个元素时,它当然可以中断).也许你可以提供比使用文本块和图像更好的解决方案?

windows microsoft-metro windows-8 winrt-xaml

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

LINQ to Entities无法识别方法'System.String [] Split(Char [])'方法,

我正在尝试实现一种方法,其中存储在数据库中的活动关键字(用逗号分隔)与用逗号分隔的给定字符串匹配.

public List<TblActivities> SearchByMultipleKeyword(string keywords)
{
    string[] keyword = keywords.Split(',');
    var results  = (from a in Entities.TblActivities
                    where a.Keywords.Split(',').Any(p => keyword.Contains(p))
                    select a).ToList();
    return results;
}
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

LINQ to Entities does not recognize the method 'System.String[] Split(Char[])' method,
and this method cannot be translated into a store expression.
Run Code Online (Sandbox Code Playgroud)

c# linq string

7
推荐指数
4
解决办法
1万
查看次数

UWP的发布包构建失败

我为Windows 10构建了一个通用应用程序,我不知道Native Tool链.当我准备创建包时,我遇到了很多错误,我找不到任何运气的解决方案.

经过几次尝试后,我决定将我的应用程序一块一块地放在一个测试项目中,看看出了什么问题,我添加了Mvvm Light 5.2的ViewModelLocator后出现了以下错误:

NUTC300F:Internal Compiler Error: Native compilation failed due to out of memory error
ILT0005: 'C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\x86\ilc\Tools\nutc_driver.exe 
    @"C:\...\Test\obj\x86\Release\ilc\intermediate\MDIL\Test.rsp"' returned exit code 1
Warning  Method 'CreateLambda' within 'System.Linq.Expressions.Expression' could not be found.
    C:\....\Test\Resources.System.Linq.Expressions.rd.xml 35 
Warning  Method 'ParameterIsAssignable' within 'System.Linq.Expressions.Expression' could not be found.
    C:\....\Test\Resources.System.Linq.Expressions.rd.xml 91 
Run Code Online (Sandbox Code Playgroud)

这是我的ViewModelLocatorClass

public class ViewModelLocator
{
    public const string HeroDetailsPageName = "HeroDetails";

    public ViewModelLocator()
    {
        ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);

        var nav = new NavigationService();
        nav.Configure(HeroDetailsPageName, typeof(HeroDetails));
        SimpleIoc.Default.Register<INavigationService>(() => nav);

        SimpleIoc.Default.Register<IDialogService, DialogService>();

        if (ViewModelBase.IsInDesignModeStatic) …
Run Code Online (Sandbox Code Playgroud)

.net-native visual-studio-2015 uwp windows-10-universal

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

如何将XElement写入已包含内容的XmlWriter

我正在尝试以流方式编写一个非常大的XML文档.而不是写一个XDocument或者XElement可能消耗太多内存的想法是,我在使用a之前编写根元素XmlWriter,然后在关闭根元素之前一个接一个地向该编写器写入许多XElements.但是,我还没有找到办法.要模拟问题,请考虑以下代码:

using System;
using System.Xml;
using System.Xml.Linq;

internal static class Program
{
    private static void Main()
    {
        var settings = new XmlWriterSettings { Encoding = Console.OutputEncoding, Indent = true };

        using (var writer = XmlWriter.Create(Console.Out, settings))
        {
            const string namespaceUri = "http://example.com/";

            writer.WriteStartElement("x", "root", namespaceUri);

            XNamespace x = namespaceUri;

            XElement element = new XElement(x + "test");

            element.Save(writer);

            writer.WriteEndElement();
        }

        Console.WriteLine();
    }
}
Run Code Online (Sandbox Code Playgroud)

该程序element.Save(writer);在行上失败,其中包括InvalidOperationException:"状态元素开始标记中的标记StartDocument将导致无效的XML文档".

这个异常的原因很明显:XElement假设它拥有整个XmlWriter,并调用WriteStartDocument()它.显然失败了,因为文档已经启动,并且已经有一个启动元素.

请注意,如果我使用XDocument,我会期待这种行为,但我不是,我正在使用XElement …

c# xml linq-to-xml

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

为 Linq Select 语句创建匿名对象

我得到一个字符串数组,其中包含属性名称。我只想在获取数据时加载这些属性,在本例中是通过实体框架从数据库获取数据。就像是:

\n\n
var result = db.myTable\n               .Where(x => x.Id == \xe2\x80\x9dsomeValue\xe2\x80\x9d)\n               .Select(y => new {y.someProperty, y.someOtherproperty, ...});\n
Run Code Online (Sandbox Code Playgroud)\n\n

如何从字符串数组创建匿名对象。我想要这样的东西:

\n\n
var MyObj = new {};\nforeach(var I in MyStrinArr)\n{\n   ... Add the properties here ...\n}\nvar result = db.myTable.Where(x => x.Id==\xe2\x80\x9dsomeValue\xe2\x80\x9d).Select(y => obj);\n
Run Code Online (Sandbox Code Playgroud)\n

c# linq

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

如何修复 CA1000 不要在泛型类型上声明静态成员

我正在使用Microsoft.CodeAnalysis.FxCopAnalyzersCA1000规则如下。

不要在泛型类型上声明静态成员。

如何纠正违规行为

要修复违反此规则的问题,请删除静态成员或将其更改为实例成员。

何时抑制警告:

不要抑制此规则的警告。以易于理解和使用的语法提供泛型可以减少学习所需的时间并提高新库的采用率。

我的代码如下。该Success方法是触发规则的方法。

public class ResultResponse
{
    internal ResultResponse(bool isSuccess)
    {
        IsSuccess = isSuccess;
    }

    public bool IsSuccess { get; }

    public static ResultResponse Failed()
        => new ResultResponse(false);
}

public class ResultResponse<T> : ResultResponse
{
    internal ResultResponse(T value, bool isSuccess)
        : base(isSuccess)
    {
        Value = value;
    }

    public T Value { get; }

    public static ResultResponse<T> Success(T value)
        => new ResultResponse<T>(value, true);
}
Run Code Online (Sandbox Code Playgroud)

我可以将构造函数公开并在上面的示例中使用它,但我也有这样的情况,我想将构造函数保留在内部以确保正确使用类型。

Success方法移至非泛型类型是正确的方法吗?

public class ResultResponse …
Run Code Online (Sandbox Code Playgroud)

c# .net-core

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

LINQ Datatable返回0而不是null合并

我有以下LINQ语句,它从数据表中计算3个值.有时,其中一些值可能包含null.我如何将null合并为0.

var striko2scrap = from myrow in Scrap.AsEnumerable()
                   where myrow.Field<string>("MachineID") == "Striko 2"
                   group myrow by myrow.Field<string>("MachineID") == "Striko 2" into g
                   select new
                   {
                        TotalScrap = g.Sum(x => x.Field<int?>("Runners") ?? 
                                         0 + x.Field<int?>("HouseIngots") ?? 
                                         0 + x.Field<int?>("Other") ?? 
                                         0)
                   } ;
Run Code Online (Sandbox Code Playgroud)

我试过了?0在不同的地方但我调试时仍然得到相同的结果. 在此输入图像描述

c# linq

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

Xamarin.Auth Facebook

好的,我正在尝试使用Xamarin.Auth对Xamarin.iOS进行非常基本的身份验证,并收到错误:"应用程序配置不允许给定URL:一个或多个给定的URL不允许应用程序的设置.它必须与网站URL或Canvas URL匹配,或者域必须是App域之一的子域."

我已经谷歌搜索了一段时间,似乎你可能再也无法使用Xam.Auth进行Facebook - 这似乎不太可能......

这是我的示例代码(没有我的FB应用程序ID) - 您会注意到它实际上是Xam的示例代码的副本:

using System;
using System.Collections.Generic;
using System.Json;
using System.Linq;
using System.Threading.Tasks;
using MonoTouch.Dialog;

#if __UNIFIED__
using Foundation;
using UIKit;
#else
using MonoTouch.Foundation;
using MonoTouch.UIKit;
#endif

namespace Xamarin.Auth.Sample.iOS
{
    [Register ("AppDelegate")]
    public partial class AppDelegate : UIApplicationDelegate
    {
        void LoginToFacebook (bool allowCancel)
        {
            var auth = new OAuth2Authenticator (
                clientId: "SOME_ID",
                scope: "",
                authorizeUrl: new Uri ("https://m.facebook.com/dialog/oauth/"),
                redirectUrl: new Uri ("http://www.facebook.com/connect/login_success.html"));

            auth.AllowCancel = allowCancel;

            // If authorization succeeds or is canceled, .Completed will be …
Run Code Online (Sandbox Code Playgroud)

c# facebook oauth-2.0 xamarin

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

我得到一个stackoverflowexception,我不知道为什么

我制作了自定义用户控件,但在设置自定义属性时遇到问题.这是我遇到问题的代码,我不知道为什么我会收到堆栈溢出异常.任何帮助将非常感激.

displayList = new List<ItemDisplay>();
foreach (var item in InventoryData2.Items)
{
    ItemDisplay id = new ItemDisplay();
    id.Item = item;
    id.Name = item.Item.ItemNumber;
    id.Location = new System.Drawing.Point(0, displayList.Count * id.Height);
    displayList.Add(id);
}


public InventoryItem Item 
{
    get { return Item; }
    set { 
        Item = value;
        lblItemNumber.Text = Item.Item.ItemNumber;
        lblTitle.Text = Item.Item.Title;
        lblModel.Text = Item.Item.Model;
        lblPrice.Text = Item.Item.Price.ToString();
    }
}
Run Code Online (Sandbox Code Playgroud)

c# stack-overflow exception

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