小编Pat*_*ick的帖子

在Xamarin XAML中,如何使用Style在RelativeLayout上设置约束?

我正在努力计算XAML语法以将约束应用于RelativeLayout使用a Style.

下面的第一个Xamarin XAML显示了一对RelativeLayout用于构造简单布局的嵌套元素(内部元素只是在我可以添加其他内容的区域周围放置边距).此版本的代码在iOS和Android上构建并运行良好.

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="App2.Page1">
    <RelativeLayout BackgroundColor="Gray">
        <RelativeLayout BackgroundColor="Maroon"
            RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent,Property=Height,Factor=0.9,Constant=0}"
            RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent,Property=Width,Factor=0.9,Constant=0}"
            RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent,Property=Height,Factor=0.05,Constant=0}"
            RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent,Property=Width,Factor=0.05,Constant=0}">
            <BoxView Color="Yellow"
                RelativeLayout.HeightConstraint="{ConstraintExpression Type=RelativeToParent,Property=Height,Factor=0.25,Constant=0}"
                RelativeLayout.WidthConstraint="{ConstraintExpression Type=RelativeToParent,Property=Width,Factor=0.25,Constant=0}"
                RelativeLayout.YConstraint="{ConstraintExpression Type=RelativeToParent,Property=Height,Factor=0.25,Constant=0}"
                RelativeLayout.XConstraint="{ConstraintExpression Type=RelativeToParent,Property=Width,Factor=0.25,Constant=0}"/>
        </RelativeLayout>
    </RelativeLayout>
</ContentPage>
Run Code Online (Sandbox Code Playgroud)

我想做的是在多个页面上使用相同的布局,所以我想把RelativeLayout约束放到一个Style.第二段代码不解析或运行,但我希望它能说明我想要实现的目标.如果我能为此获得正确的语法,Style那么可以将其移出到共享文件中,这样我就可以轻松地在多个实例中重用它ContentPage.

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="App2.Page2">
    <ContentPage.Resources>
        <ResourceDictionary>
            <Style x:Key="LayoutStyle" TargetType="RelativeLayout">
                <Setter Property="BackgroundColor" Value="Maroon"/>
                <Setter Property="HeightConstraint">
                    <Setter.Value>"Type=RelativeToParent,Property=Height,Factor=0.9,Constant=0"</Setter.Value>
                </Setter>
                <Setter Property="WidthConstraint">
                    <Setter.Value>"Type=RelativeToParent,Property=Width,Factor=0.9,Constant=0"</Setter.Value>
                </Setter>
                <Setter Property="YConstraint">
                    <Setter.Value>"Type=RelativeToParent,Property=Height,Factor=0.05,Constant=0</Setter.Value>
                </Setter>
                <Setter …
Run Code Online (Sandbox Code Playgroud)

xaml xamarin.forms

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

如何在XML模式中指定唯一值

我无法让xs:unique说明符在XML文件中工作.我似乎无法找到一个有效的XPath.我对这个问题中的代码数量表示道歉,但我非常感谢任何可以在下面指出我做错的人.无论我做什么,我都无法在元素中获取@ref属性来报告错误,因为我复制了值(每个ref必须是唯一的).

非常感谢任何帮助或信息指示.

亲切的愿望,帕特里克

这是我的架构:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="Artworks"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:aw="http://www.fourthwish.co.uk/data/Artworks.xsd"
xmlns="http://www.fourthwish.co.uk/data/Artworks.xsd"
targetNamespace="http://www.fourthwish.co.uk/data/Artworks.xsd"
elementFormDefault="qualified"
>
<xs:element name="artworks">
    <xs:complexType>
    <xs:sequence minOccurs="0" maxOccurs="unbounded">
            <xs:element name="artwork" type="ArtworkType">
                <xs:unique name="uniqueRef">
                    <xs:selector xpath="artwork"/>
                    <xs:field xpath="@ref"/>
                </xs:unique>
            </xs:element>
        </xs:sequence>
    </xs:complexType>
</xs:element>
<xs:complexType name="ArtworkType">
    <xs:sequence>
        <xs:element name="title" type="xs:string"/>
    </xs:sequence>
    <xs:attribute name="ref" type="xs:nonNegativeInteger"/>
</xs:complexType>
</xs:schema>
Run Code Online (Sandbox Code Playgroud)

这是我的XML文件:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<artworks
xmlns="http://www.fourthwish.co.uk/data/Artworks.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.fourthwish.co.uk/data/Artworks.xsd Artworks.xsd"
>
<artwork ref="1">
    <title>Title String</title>
</artwork>
<artwork ref="1">
    <title>Title String</title>
</artwork>
</artworks>
Run Code Online (Sandbox Code Playgroud)

为什么我的重复参考值没有出错?Arrrggghhh!我已经阅读了互联网上的所有内容.请帮助别人.

xml xpath xsd

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

为什么C#三元运算符需要等效if()语句的强制转换?

我不明白为什么以下两个代码语句不相同:

if( _hexColourString.Length >= 8 )
    _bytes[ 3 ] = byte.Parse( _hexColourString.Substring( start + 6, 2 ), NumberStyles.AllowHexSpecifier );
else
    _bytes[ 3 ] = 0x00;


_bytes[ 3 ] = ( _hexColourString.Length >= 8 ) ? byte.Parse( _hexColourString.Substring( start + 6, 2 ), NumberStyles.AllowHexSpecifier ) : 0x00;
Run Code Online (Sandbox Code Playgroud)

第一个编译没有问题,而第二个说我需要将int转换为一个字节.修复它显然没问题,但我想理解为什么演员是必要的.

c# casting ternary-operator

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

为什么SQL Server不识别存储过程但是它运行它没有错误?

我正在使用MSSQL Management Studio.我已经使用CREATE PROCEDURE创建了一个存储过程,现在正在使用现在包含ALTER PROCEDURE的脚本进行处理.此语句后面的过程名称用红色下划线,编辑器说它无法找到它.尽管如此,存储过程显示在左侧树视图中,我可以右键单击它并运行它而不会出现错误.当我这样做时,生成的临时脚本运行存储过程...

EXEC @return_value = [dbo].[SP_V00_CreateABCTable]
Run Code Online (Sandbox Code Playgroud)

还强调了红色的名称.

我不明白编辑器如何声称该对象不存在但是然后运行它没有错误.有谁知道可能会发生什么?

t-sql sql-server stored-procedures

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