2016-06-24 10 views
2

Ich muss ein benutzerdefiniertes UserControl in einem Stackpannel platzieren. Ich habe dieses Usercontrol:Windows 10 Universal App UserControl im Stackpanel

<UserControl 
    x:Class="ScannerApp.Custom_Controls.LocationAndQuantity" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="using:ScannerApp.Custom_Controls" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d" 
    d:DesignHeight="20" 
    d:DesignWidth="400"> 

    <Grid Background="White"> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="100*"/> 
      <ColumnDefinition Width="80*"/> 
      <ColumnDefinition Width="100*"/> 
     </Grid.ColumnDefinitions> 
     <Border x:Name="border" Background="Red" BorderThickness="1" HorizontalAlignment="Left" Height="20" VerticalAlignment="Top" Width="143"> 
      <TextBlock x:Name="locationTxt" Text="location" HorizontalAlignment="Center"></TextBlock> 
     </Border> 
     <TextBlock x:Name="quantityTxt" Text="quantity" Grid.Column="2" HorizontalAlignment="Center" TextWrapping="Wrap" VerticalAlignment="Top"/> 
    </Grid> 
</UserControl> 

und eine Seite mit Stackpanel

<Page 
    x:Class="ScannerApp.FindPN___STEP2" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="using:ScannerApp" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d"> 

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> 
     ... 
     <StackPanel> 
      <!--here I want to place the userControls--> 
     </StackPanel> 
    </Grid> 
</Page> 

ich einige sollutions wie <controls: ...> //this could not be found by intellisense even oder

versucht
<my:UserControlName Grid.Column="2" Grid.Row="2" ... /> 
<Window ... 
    xmlns:my="clr-namespace:AssemblyName" 
    ... 
/> 

aber ich habe nicht das Fenster hier .. Ich habe versucht, etwas Ähnliches in die Seite einzufügen, aber ich weiß nicht genau, was ich dort eingeben soll.

+0

Sie einen Namespace zu Ihrem Usercontrol hinzufügen müssen, um zu schreiben, so setze einen neuen Namensraum rechts unter 'xmlns: mc =" http [...] 'wie' xmlns: myControls = "clr-namespace: MeinAppNamespace;" danach kannst du dein Steuerelement wie '' verwenden –

Antwort

1

Wie in den Kommentaren gesagt, müssen Sie Ihren XAML reparieren. Wenn Sie benutzerdefinierte Steuerelemente verwenden möchten, müssen Sie dem Compiler mitteilen, woher die Steuerelemente stammen.

Bei Steuert Sie Namespace ist

ScannerApp.Custom_Controls

Sie haben die Seite XAML als

<Page 
    x:Class="ScannerApp.FindPN___STEP2" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="clr-namespace:ScannerApp.Custom_Controls" <!--FIXED HERE--> 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d"> 

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> 
    ... 
    <StackPanel> 
     <local:NameOfYourControl x:Name="MyNewControl" /> <!--Properties can be added--> 
    </StackPanel> 
    </Grid> 
</Page>