I am trying to create a custom style panel (StyledStackPanel) which is identical to regular StackPanel, that has a custom style.
For example - if the style is simply to add an underline, by writing:
<StyledStackPanel>
    <!--User content goes here-->
</StyledStackPanel>
I would like to receive the same appearance as if I wrote:
<StackPanel>
    <!--User content goes here--&开发者_开发问答gt;
</StackPanel>
<Border Height="1" BorderBrush="Blue"/>
If StackPanel was a Control, I could have replace the DataTemplate of that control. However, it inherits Panel which inherits FrameworkElement. 
StackPanel?There is no way to set a ControlTemplate for a panel, but you have several options:
- Create a custom/user control that has the StackPanel as a child. 
- Inherit from StackPanel and override OnRender to draw your custom style (you may also need to override MeasureOverride and ArrangeOverride to add a little space around the panel's children for your drawing. 
- Inherit directly from Panel and override OnRender, MeasureCore and ArrangeCore - if you need to use the panel is a specific way and you don't need all of StackPanel's option this maybe the easiest way since the StackPanel layout algorithm is simple. 
- Inherit from Decorator (if you do your drawing in code) or ContentControl (if you want to use ControlTemplate) and warp your panel with it when you use it: - <l:PanelStyle> <StackPanel> .. <StackPanel> </l:PanelStyle>
- Write the style for ItemsControl, ItemsControl has a ControlTemplate that you can set and basically wraps a panel (by default it's a vertical StackPanel). 
I would go with option 4 if you need access to the StackPanel's properties or 5 if you don't.
You should make a normal custom control that adds its child elements to an inner StackPanel.
For example:
[ContentProperty("Children")]
public class StyledStackPanel : UserControl {
    public UIElementCollection Children { get { return stackPanel.Children; } }
}
(Untested)
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论