WPFのGroupBoxコントロールはコンテンツとして1つのWPFコントロールのみを受け入れるため、最初にすべてのプロパティをDockPanelコントロールにラップする必要がありました。
次のxslスタイルシートを使用して、コードを後で表示されるXAMLコードスニペットに変換しました。スタイルシート(スニペット):
<!-- Default attribute processing -->
<xsl:template name="process-element">
<xsl:param name="attr" />
<!-- Process all attributes and elements which are going to be
transformed to attributes -->
<xsl:apply-templates select="@*|*" mode="to-attr" />
<!-- Add extra attribute -->
<xsl:if test="$attr">
<xsl:attribute name="{substring-after($attr, '|')}">
<xsl:value-of select="@*[local-name() = substring-before($attr, '|')]" />
</xsl:attribute>
</xsl:if>
<!-- Process children elements -->
<xsl:apply-templates select="*" />
</xsl:template>
<!-- Map GroupBoxWrapper into GroupBox -->
<xsl:template match="GroupBoxWrapper">
<xsl:element name="GroupBox">
<!-- TODO: Add DockPanel Element and move "cursor" one level upwards -->
<!--<xsl:element name="DockPanel">-->
<xsl:call-template name="process-element">
<xsl:with-param name="attr"/>
</xsl:call-template>
<!--</xsl:element>-->
</xsl:element>
</xsl:template>
これは、生成されたコードXAMLです。
<GroupBox Name="groupbox1" DockPanel.Dock="Left, Right, Top, Bottom" Width="1092" Height="125" Background="Transparent" Foreground="#0046D5" Visibility="visible" BorderThickness="1,1,1,1" FontFamily="Tahoma" FontSize="9" TabIndex="0" IsTabStop="False">
<DockPanel Name="panel4" DockPanel.Dock="Top" Width="1078" Height="25" Background="Transparent" Visibility="visible">
<Label Name="lblName" DockPanel.Dock="Left" Width="100" Height="25" Background="Transparent" Foreground="Black" Visibility="visible" BorderThickness="1,1,1,1" FontFamily="Tahoma" FontSize="9" TabIndex="0" IsTabStop="False" Content="Name:" />
<TextBox Name="txtName" DockPanel.Dock="Left" Width="100" Height="25" Background="Azure" Foreground="Black" Visibility="visible" BorderThickness="1,1,1,1" FontFamily="Tahoma" FontSize="9" TabIndex="1" IsTabStop="True" Text="" />
</DockPanel>
<DockPanel Name="panel5" DockPanel.Dock="Top" Width="1078" Height="25" Background="Transparent" Visibility="visible">
<Label Name="lblLastName" DockPanel.Dock="Left" Width="100" Height="25" Background="Transparent" Foreground="Black" Visibility="visible" BorderThickness="1,1,1,1" FontFamily="Tahoma" FontSize="9" TabIndex="0" IsTabStop="False" Content="Lastname:" />
<TextBox Name="txtLastName" DockPanel.Dock="Left" Width="100" Height="25" Background="Azure" Foreground="Black" Visibility="visible" BorderThickness="1,1,1,1" FontFamily="Tahoma" FontSize="9" TabIndex="1" IsTabStop="True" Text="" />
</DockPanel>
<DockPanel Name="panel6" DockPanel.Dock="Top" Width="1078" Height="25" Background="Transparent" Visibility="visible">
<Label Name="label4" DockPanel.Dock="Left" Width="100" Height="25" Background="Transparent" Foreground="Black" Visibility="visible" BorderThickness="1,1,1,1" FontFamily="Tahoma" FontSize="9" TabIndex="0" IsTabStop="False" Content="Age:" />
<TextBox Name="textbox3" DockPanel.Dock="Left" Width="100" Height="25" Background="Azure" Foreground="Black" Visibility="visible" BorderThickness="1,1,1,1" FontFamily="Tahoma" FontSize="9" TabIndex="1" IsTabStop="True" Text="" />
</DockPanel>
<DockPanel Name="panel14" DockPanel.Dock="Top" Width="1078" Height="25" Background="Transparent" Visibility="visible">
<Label Name="label9" DockPanel.Dock="Left" Width="100" Height="25" Background="Transparent" Foreground="Black" Visibility="visible" BorderThickness="1,1,1,1" FontFamily="Tahoma" FontSize="9" TabIndex="0" IsTabStop="False" Content="Gender:" />
<RadioButton Name="radiobutton1" DockPanel.Dock="Left" Width="75" Height="25" Background="Transparent" Foreground="Black" Visibility="visible" BorderThickness="1,1,1,1" FontFamily="Tahoma" FontSize="9" TabIndex="1" IsTabStop="True" Content="Male" />
<RadioButton Name="radiobutton2" DockPanel.Dock="Left" Width="75" Height="25" Background="Transparent" Foreground="Black" Visibility="visible" BorderThickness="1,1,1,1" FontFamily="Tahoma" FontSize="9" TabIndex="2" IsTabStop="True" Content="Female" />
</DockPanel>
</GroupBox>
問題は、GroupBoxにWPFでは不可能な4つの要素が含まれていることです。そのため、これらのコントロールを1つのDockPanelにラップする必要があります。
行のコメントを外すと<xsl:element name="DockPanel">
、XAMLコードは次のようになります。
<GroupBox> <!-- attributes should appear on this line -->
<DockPanel Name="groupbox1" DockPanel.Dock="Left, Right, Top, Bottom" Width="1092" Height="125" Background="Transparent" Foreground="#0046D5" Visibility="visible" BorderThickness="1,1,1,1" FontFamily="Tahoma" FontSize="9" TabIndex="0" IsTabStop="False">
<DockPanel Name="panel4" DockPanel.Dock="Top" Width="1078" Height="25" Background="Transparent" Visibility="visible">
<Label Name="lblName" DockPanel.Dock="Left" Width="100" Height="25" Background="Transparent" Foreground="Black" Visibility="visible" BorderThickness="1,1,1,1" FontFamily="Tahoma" FontSize="9" TabIndex="0" IsTabStop="False" Content="Name:" />
<TextBox Name="txtName" DockPanel.Dock="Left" Width="100" Height="25" Background="Azure" Foreground="Black" Visibility="visible" BorderThickness="1,1,1,1" FontFamily="Tahoma" FontSize="9" TabIndex="1" IsTabStop="True" Text="" />
</DockPanel>
<DockPanel Name="panel5" DockPanel.Dock="Top" Width="1078" Height="25" Background="Transparent" Visibility="visible">
<Label Name="lblLastName" DockPanel.Dock="Left" Width="100" Height="25" Background="Transparent" Foreground="Black" Visibility="visible" BorderThickness="1,1,1,1" FontFamily="Tahoma" FontSize="9" TabIndex="0" IsTabStop="False" Content="Lastname:" />
<TextBox Name="txtLastName" DockPanel.Dock="Left" Width="100" Height="25" Background="Azure" Foreground="Black" Visibility="visible" BorderThickness="1,1,1,1" FontFamily="Tahoma" FontSize="9" TabIndex="1" IsTabStop="True" Text="" />
</DockPanel>
<DockPanel Name="panel6" DockPanel.Dock="Top" Width="1078" Height="25" Background="Transparent" Visibility="visible">
<Label Name="label4" DockPanel.Dock="Left" Width="100" Height="25" Background="Transparent" Foreground="Black" Visibility="visible" BorderThickness="1,1,1,1" FontFamily="Tahoma" FontSize="9" TabIndex="0" IsTabStop="False" Content="Age:" />
<TextBox Name="textbox3" DockPanel.Dock="Left" Width="100" Height="25" Background="Azure" Foreground="Black" Visibility="visible" BorderThickness="1,1,1,1" FontFamily="Tahoma" FontSize="9" TabIndex="1" IsTabStop="True" Text="" />
</DockPanel>
<DockPanel Name="panel14" DockPanel.Dock="Top" Width="1078" Height="25" Background="Transparent" Visibility="visible">
<Label Name="label9" DockPanel.Dock="Left" Width="100" Height="25" Background="Transparent" Foreground="Black" Visibility="visible" BorderThickness="1,1,1,1" FontFamily="Tahoma" FontSize="9" TabIndex="0" IsTabStop="False" Content="Gender:" />
<RadioButton Name="radiobutton1" DockPanel.Dock="Left" Width="75" Height="25" Background="Transparent" Foreground="Black" Visibility="visible" BorderThickness="1,1,1,1" FontFamily="Tahoma" FontSize="9" TabIndex="1" IsTabStop="True" Content="Male" />
<RadioButton Name="radiobutton2" DockPanel.Dock="Left" Width="75" Height="25" Background="Transparent" Foreground="Black" Visibility="visible" BorderThickness="1,1,1,1" FontFamily="Tahoma" FontSize="9" TabIndex="2" IsTabStop="True" Content="Female" />
</DockPanel>
</DockPanel>
</GroupBox>
GroupBoxのインテントが内部のGroupBox要素をネストするDockPanel要素にあるすべての属性。
DockPanel要素を作成する方法を理解し(チェック)、GroupBox要素に移動してプロセス要素テンプレートを呼び出す必要があります。
何か案は?