我使用 Expression Blend 创建了一个自定义控件:
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="MyProject.EditableField"
d:DesignWidth="286" d:DesignHeight="20">
<Grid x:Name="LayoutRoot">
<TextBlock HorizontalAlignment="Left" Width="95" Text="Label:" TextWrapping="Wrap" x:Name="Label" FontSize="12"/>
<TextBox Margin="99,0,0,0" x:Name="Value" Text="Value" TextWrapping="Wrap"/>
</Grid>
</UserControl>
它包含一个 TextBlock 标签和一个 TextBox 值。我想要的是使用它们自己的标签和值将其中的多个添加到我的 XAML 中,可能是这样的:
<MyProject:EditableField Margin="30,180,0,0" Height="20" HorizontalAlignment="Left" VerticalAlignment="Top" Width="286" x:Name="FaxNumber">
<Label>
<Text>Fax number:</Text>
</Label>
<Value>
<Contents>
111-222-333
</Contents>
</Value>
</MyProject:EditableField>
当我说也许,这显然是行不通的。添加它们的正确语法是什么?