我已經看過了這裏的其他自定義控件創建問題以及其他在線資源,但是我失去了如何創建自定義控件不需要C#代碼隱藏文件。由於我的項目是純IronPython,我不知道如何將C#代碼與它整合在一起。在IronPython中創建自定義WPF控件:一個由標準控件構成的控件
我想要做的甚至不是那麼複雜;沒有凌亂的風格或渲染轉換或任何東西。我只是試圖創建一組現有的複合控件,以便我可以通過程序添加/刪除這些複合控件。例如,我有這樣的分組框:
正如你所看到的,它只是一個帶有文本框,並在頭一個ComboBox組框,其機身由含有一些的CheckBox一個UniformGrid填充。這裏是XAML:
<GroupBox Name="DO1">
<GroupBox.Header>
<DockPanel>
<TextBlock VerticalAlignment="Center">DO1</TextBlock>
<ComboBox Name="DO1DeviceList" Margin="3 0 0 0" ItemsSource="{Binding DOtable}">
</ComboBox>
</DockPanel>
</GroupBox.Header>
<UniformGrid Rows="1">
<StackPanel>
<Label Content="3W1L" HorizontalAlignment="Center" VerticalAlignment="Center" />
<CheckBox Name="DO1o1" IsChecked="{Binding o1}" HorizontalAlignment="Center" VerticalAlignment="Center" />
<Label Content="1" HorizontalAlignment="Center" VerticalAlignment="Center" />
</StackPanel>
<StackPanel>
<Label Content="3W3V" HorizontalAlignment="Center" VerticalAlignment="Center" />
<CheckBox Name="DO1o2" IsChecked="{Binding o2}" HorizontalAlignment="Center" VerticalAlignment="Center" />
<Label Content="2" HorizontalAlignment="Center" VerticalAlignment="Center" />
</StackPanel>
<StackPanel>
<Label Content="Ni" HorizontalAlignment="Center" VerticalAlignment="Center" />
<CheckBox Name="DO1o3" IsChecked="{Binding o3}" HorizontalAlignment="Center" VerticalAlignment="Center" />
<Label Content="3" HorizontalAlignment="Center" VerticalAlignment="Center" />
</StackPanel>
<StackPanel>
<Label Content="2W1" HorizontalAlignment="Center" VerticalAlignment="Center" />
<CheckBox Name="DO1o4" IsChecked="{Binding o4}" HorizontalAlignment="Center" VerticalAlignment="Center" />
<Label Content="4" HorizontalAlignment="Center" VerticalAlignment="Center" />
</StackPanel>
<StackPanel>
<Label Content="Vac2" HorizontalAlignment="Center" VerticalAlignment="Center" />
<CheckBox Name="DO1o5" IsChecked="{Binding o5}" HorizontalAlignment="Center" VerticalAlignment="Center" />
<Label Content="5" HorizontalAlignment="Center" VerticalAlignment="Center" />
</StackPanel>
<StackPanel>
<Label Content="3W4V" HorizontalAlignment="Center" VerticalAlignment="Center" />
<CheckBox Name="DO1o6" IsChecked="{Binding o6}" HorizontalAlignment="Center" VerticalAlignment="Center" />
<Label Content="6" HorizontalAlignment="Center" VerticalAlignment="Center" />
</StackPanel>
<StackPanel>
<Label Content="Cu" HorizontalAlignment="Center" VerticalAlignment="Center" />
<CheckBox Name="DO1o7" IsChecked="{Binding o7}" HorizontalAlignment="Center" VerticalAlignment="Center" />
<Label Content="7" HorizontalAlignment="Center" VerticalAlignment="Center" />
</StackPanel>
<StackPanel>
<Label Content="3W2L" HorizontalAlignment="Center" VerticalAlignment="Center" />
<CheckBox Name="DO1o8" IsChecked="{Binding o8}" HorizontalAlignment="Center" VerticalAlignment="Center" />
<Label Content="8" HorizontalAlignment="Center" VerticalAlignment="Center" />
</StackPanel>
</UniformGrid>
</GroupBox>
我讀過有關控制合成,分組一堆控制到一個單一的控制。我想讓整個GroupBox成爲一個我可以通過程序添加或刪除的控件。我如何用IronPython實現這一目標?