1

我创建了一个自定义用户控件,它看起来像这样:

用户控制

控件的 XAML 是:

<Grid>
    <Label Content="Job #"    Height="28" HorizontalAlignment="Left" Margin="6,14,0,0"  Name="label1" Style="{StaticResource MyLabel2}" VerticalAlignment="Top" Width="48" HorizontalContentAlignment="Right" />
    <Label Content="Customer" Height="28" HorizontalAlignment="Left" Margin="6,41,0,0"  Name="label2" Style="{StaticResource MyLabel2}" VerticalAlignment="Top" Width="48" HorizontalContentAlignment="Right" />
    <Label Content="Location" Height="28" HorizontalAlignment="Left" Margin="6,68,0,0"  Name="label3" Style="{StaticResource MyLabel2}" VerticalAlignment="Top" Width="48" HorizontalContentAlignment="Right" />
    <Label Content="Crossing" Height="28" HorizontalAlignment="Left" Margin="6,95,0,0"  Name="label4" Style="{StaticResource MyLabel2}" VerticalAlignment="Top" Width="48" HorizontalContentAlignment="Right" />
    <Label Content="Engineer" Height="28" HorizontalAlignment="Left" Margin="6,122,0,0" Name="label5" Style="{StaticResource MyLabel2}" VerticalAlignment="Top" Width="48" HorizontalContentAlignment="Right" />
    <Label Content="Probe #"  Height="28" HorizontalAlignment="Left" Margin="6,149,0,0" Name="label6" Style="{StaticResource MyLabel2}" VerticalAlignment="Top" Width="48" HorizontalContentAlignment="Right" />

    <Label Content="Default" Height="28" HorizontalAlignment="Left" Margin="53,14,0,0"  Name="lblJob"      Style="{StaticResource MyLabel3}" VerticalAlignment="Top" Width="120" />
    <Label Content="Default" Height="28" HorizontalAlignment="Left" Margin="53,41,0,0"  Name="lblCustomer" Style="{StaticResource MyLabel3}" VerticalAlignment="Top" Width="120" />
    <Label Content="Default" Height="28" HorizontalAlignment="Left" Margin="53,68,0,0"  Name="lblLocation" Style="{StaticResource MyLabel3}" VerticalAlignment="Top" Width="120" />
    <Label Content="Default" Height="28" HorizontalAlignment="Left" Margin="53,95,0,0"  Name="lblCrossing" Style="{StaticResource MyLabel3}" VerticalAlignment="Top" Width="120" />
    <Label Content="Default" Height="28" HorizontalAlignment="Left" Margin="53,122,0,0" Name="lblEngineer" Style="{StaticResource MyLabel3}" VerticalAlignment="Top" Width="120" />
    <Label Content="Default" Height="28" HorizontalAlignment="Left" Margin="53,149,0,0" Name="lblProbe"    Style="{StaticResource MyLabel3}" VerticalAlignment="Top" Width="120" />

    <Label Content="Away"        Height="28" HorizontalAlignment="Left" Margin="204,41,0,0"  Name="label14" Style="{StaticResource MyLabel2}" VerticalAlignment="Top" Width="55" />
    <Label Content="Elevation"   Height="28" HorizontalAlignment="Left" Margin="204,68,0,0"  Name="label15" Style="{StaticResource MyLabel2}" VerticalAlignment="Top" Width="55" />
    <Label Content="Right"       Height="28" HorizontalAlignment="Left" Margin="204,95,0,0"  Name="label16" Style="{StaticResource MyLabel2}" VerticalAlignment="Top" Width="55" />
    <Label Content="Inclination" Height="28" HorizontalAlignment="Left" Margin="204,122,0,0" Name="label17" Style="{StaticResource MyLabel2}" VerticalAlignment="Top" Width="55" />
    <Label Content="Baseline"    Height="28" HorizontalAlignment="Left" Margin="204,149,0,0" Name="label18" Style="{StaticResource MyLabel2}" VerticalAlignment="Top" Width="55" />

    <Label Content="Default" Height="28" HorizontalAlignment="Left" Margin="258,41,0,0"  Name="lblAway"        Style="{StaticResource MyLabel3}" VerticalAlignment="Top" Width="120" />
    <Label Content="Default" Height="28" HorizontalAlignment="Left" Margin="258,68,0,0"  Name="lblElevation"   Style="{StaticResource MyLabel3}" VerticalAlignment="Top" Width="120" />
    <Label Content="Default" Height="28" HorizontalAlignment="Left" Margin="258,95,0,0"  Name="lblRight"       Style="{StaticResource MyLabel3}" VerticalAlignment="Top" Width="120" />
    <Label Content="Default" Height="28" HorizontalAlignment="Left" Margin="258,122,0,0" Name="lblInclination" Style="{StaticResource MyLabel3}" VerticalAlignment="Top" Width="120" />
    <Label Content="Default" Height="28" HorizontalAlignment="Left" Margin="258,149,0,0" Name="lblBaseline"    Style="{StaticResource MyLabel3}" VerticalAlignment="Top" Width="120" />

    <Label Content="Entry"   Height="28" HorizontalAlignment="Left" Margin="338,12,0,0" Name="label13"  Style="{StaticResource MyLabel2}" VerticalAlignment="Top" Width="40" />
    <Label Content="Default" Height="28" HorizontalAlignment="Left" Margin="377,12,0,0" Name="lblEntry" Style="{StaticResource MyLabel3}" VerticalAlignment="Top" Width="120" />

    <Label Content="Exit"    Height="28" HorizontalAlignment="Left" Margin="521,12,0,0" Name="label25" Style="{StaticResource MyLabel2}" VerticalAlignment="Top" Width="40" />
    <Label Content="Default" Height="28" HorizontalAlignment="Left" Margin="560,12,0,0" Name="lblExit" Style="{StaticResource MyLabel3}" VerticalAlignment="Top" Width="120" />

    <Label Content="Units"   Height="28" HorizontalAlignment="Left" Margin="706,12,0,0" Name="label27"  Style="{StaticResource MyLabel2}" VerticalAlignment="Top" Width="40" />
    <Label Content="Default" Height="28" HorizontalAlignment="Left" Margin="745,12,0,0" Name="lblUnits" Style="{StaticResource MyLabel3}" VerticalAlignment="Top" Width="120" />

    <DataGrid AutoGenerateColumns="True" Height="275" Margin="12,186,0,0" Name="dataGrid1" VerticalAlignment="Top" HorizontalAlignment="Left" Width="849" />
</Grid>

然而,当我将它添加到将要进入的窗口时,它看起来像这样:

添加

窗口的 XAML 是:

<Grid>
    <SurveyReport:SurveyReport Margin="0,12,0,0" Height="727" VerticalAlignment="Top" HorizontalAlignment="Left" Width="1425" />
</Grid>

现在,当我运行程序时,它会以应有的方式出现。但在设计师看来,一切都一团糟。我所有的其他自定义控件看起来都是它们应该的样子。正是这一点给我带来了问题。是否有一个原因?

4

0 回答 0