WPF OnRender Z-orderコントロール?
質問
子供の素敵なカスタムレイアウトを実装するカスタムパネルがあります。パネルに追加のグラフィックを追加して、OnRenderをオーバーライドして長方形などを追加したいと考えています。OnRenderが背景にのみ追加されるように見えることを除いて、それはうまく機能します。あなたのオンレンダーの絵を子供たちの上に置く方法はありますか?
パネルの例...
public class RenderPanel : WrapPanel
{
protected override void OnRender(DrawingContext drawingContext)
{
base.OnRender(drawingContext);
drawingContext.DrawRectangle(Brushes.Red,
new Pen(Brushes.Black, 2),
new Rect(0, 0, 100, 100));
}
}
...この方法で使用...
<Grid>
<my:RenderPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Button Margin="10" Content="Hello"/>
<Button Margin="10" Content="Hello"/>
<Button Margin="10" Content="Hello"/>
<Button Margin="10" Content="Hello"/>
</my:RenderPanel>
</Grid>
解決
私はあなたの「renderpanel」をキャンバスから継承し、それをラッパネルの上に置き、必要に応じてzindexを指定します。このようなものは機能するはずです:
<Grid>
<WrapPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Canvas.ZIndex="0">
<Button Margin="10" Content="Hello"/>
<Button Margin="10" Content="Hello"/>
<Button Margin="10" Content="Hello"/>
<Button Margin="10" Content="Hello"/>
</WrapPanel>
<my:RenderPanel HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Canvas.ZIndex="1" />
</Grid>
所属していません StackOverflow