0

シンプルな WinRT デモ プロジェクトに 2 つの非常にシンプルな UserControls があります。Viewmodel はありません。ほとんどの場合、レイアウト調査用の色付きのボックスのみです。最初に作成した UserControl は正常に動作します。2 番目の非常によく似たものは、どのプロパティにもバインドされず、空白として表示されます。

最初の UserControl は次のようになります。

    <UserControl
    x:Class="Demo.SmallStartTile"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Demo"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    x:Name="SmallStartTileUC"
    d:DesignHeight="300"
    d:DesignWidth="400">


    <Grid x:Name="SmallTileGrid"
        Margin="0,0,8,8"
        Background="{Binding Background, ElementName=SmallStartTileUC}"
        >

        <Rectangle
            Stroke="{Binding BorderBrush, ElementName=SmallStartTileUC}"
            Grid.RowSpan="2"
            />

        <TextBlock x:Name="SmallTileTitle" 
            Text="{Binding TileText, ElementName=SmallStartTileUC}" 
            Style="{StaticResource SmallTileHeader}"/>

        <Path x:Name="IconPath" 
            Style="{StaticResource SmallTileIcon}" 
            Data="{Binding TileIconPathData, ElementName=SmallStartTileUC}" />

    </Grid>




    </UserControl>

namespace Demo
{
    public sealed partial class SmallStartTile : UserControl
    {
    public static DependencyProperty TileTextProperty = DependencyProperty.Register("TileText", typeof(string), typeof(SmallStartTile), new PropertyMetadata("tile content"));

    public string TileText
    {
        get { return (string)GetValue(TileTextProperty); }
        set { SetValue(TileTextProperty, value); }
    }


    public static DependencyProperty TileIconPathDataProperty = DependencyProperty.Register("TileIconPathData", typeof(string), typeof(SmallStartTile), new PropertyMetadata("F0"));

    public string TileIconPathData
    {
        get { return (string)GetValue(TileIconPathDataProperty); }
        set { SetValue(TileIconPathDataProperty, value); }
    }



    public SmallStartTile()
    {
        this.InitializeComponent();
    }
}

}

2 つ目は、[新しい項目を追加] をクリックし、Blend で UserControl を選択して、最初のものと同じように作成しました。

<UserControl
x:Class="Demo.SmallMediaTile"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Demo"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Name="SmallMediaTileUC"
d:DesignHeight="300"
d:DesignWidth="400">

<Grid 
    Margin="0,0,8,8"
    Background="{Binding Background, ElementName=SmallMediaTileUC}"
    >

    <Grid.RowDefinitions>
        <RowDefinition/>
        <RowDefinition Height="Auto"/>
    </Grid.RowDefinitions>

    <Rectangle 
        Stroke="{Binding BorderBrush, ElementName=SmallMediaTileUC}"
        Grid.RowSpan="2"
        />

    <Viewbox 
        Margin="30" 
        Child="{Binding Content, ElementName=SmallMediaTileUC}">
    </Viewbox>

    <TextBlock 
        Grid.Row="1" 
        Text="{Binding SourceText, ElementName=SmallMediaTileUC}" 
        Style="{StaticResource SmallMusicTileHeader}"/>

</Grid>

</UserControl>


namespace Demo
{
    public sealed partial class SmallMediaTile : UserControl
    {

    public static DependencyProperty SourceTextProperty = DependencyProperty.Register("SourceText", typeof(string), typeof(SmallMediaTile), new PropertyMetadata("source"));

    public string SourceText
    {
        get { return (string)GetValue(SourceTextProperty); }
        set { SetValue(SourceTextProperty, value); }
    }



    public SmallMediaTile()
    {
        this.InitializeComponent();
    }
}

}

次のように、メイン ページで UserControl を使用します。

                            <local:SmallMediaTile x:Name="Source1Tile"
                            Grid.Column="0" Grid.Row="0"
                            SourceText="Radio"
                            Background="Blue"
                            BorderBrush="Red">
                            <local:SmallMediaTile.Content>
                            <Canvas x:Name="radio_icon" Height="68" Width="34">
                                <Path Data="F1M299.6182,396.2988C299.6182,389.7208,297.0722,383.5548,292.4572,378.8398L288.6162,382.6758C292.2022,386.3718,294.1842,391.1778,294.1842,396.2988C294.1842,401.4238,292.2022,406.2368,288.6162,409.9328L292.4572,413.7738C297.0722,409.0538,299.6182,402.8808,299.6182,396.2988" Fill="White" Height="34.934" Canvas.Left="0" Stretch="Fill" Canvas.Top="16.501" Width="11.002"/>
                                <Path Data="F1M311.1738,396.2988C311.1738,386.6278,307.4348,377.5528,300.6788,370.6208L296.8258,374.4618C302.5658,380.3698,305.7398,388.0798,305.7398,396.2988C305.7398,404.5218,302.5658,412.2298,296.8258,418.1428L300.6788,421.9898C307.4348,415.0498,311.1738,405.9718,311.1738,396.2988" Fill="White" Height="51.369" Canvas.Left="8.21" Stretch="Fill" Canvas.Top="8.282" Width="14.348"/>
                                <Path Data="F1M322.7578,396.2988C322.7578,383.5298,317.8508,371.5348,308.9638,362.3388L305.1168,366.1748C312.9758,374.3538,317.3338,384.9778,317.3338,396.2988C317.3338,407.6208,312.9758,418.2488,305.1168,426.4268L308.9638,430.2748C317.8508,421.0698,322.7578,409.0798,322.7578,396.2988" Fill="White" Height="67.936" Canvas.Left="16.501" Stretch="Fill" Canvas.Top="0" Width="17.641"/>
                            </Canvas>
                            </local:SmallMediaTile.Content>
                        </local:SmallMediaTile>

1 つ目はすべてのプロパティと表示を期待どおりに取得しますが、2 つ目は Viewbox のコンテンツのみを取得します。SOを調べてグーグルで調べましたが、問題が何であるかわかりません。これが長文である場合は申し訳ありません。

4

2 に答える 2

0

前述のように、問題はUserControlのコンテンツを一度しか設定できないことです。ビューボックスコンテンツをUserControlコンテンツにバインドすると、既存のXAMLが置き換えられます。だから、空白のボックスですが、私が渡すもののために。私が望んでいたことをするために、私はカスタムコントロールを作成する必要があると思います。助けてくれてありがとう!

于 2013-02-15T00:08:11.800 に答える
0

あなたのルートGridは の として設定されてContentUserControlますが、 はそのプロパティをそのアセンダントである のViewboxにバインドしようとしています。ルートは既に の親であり、XAML コントロールは UI の 1 か所にしか存在できないため、これは許可されません。ChildContentUserControlGridUserControl

于 2013-02-07T19:01:58.107 に答える