题
目前,我有它的应用程序,它依赖于transpareny的影响。然而,这证明是一个绝对的疼痛在preverial的背后!它作为Im学习并不处理与透明度,特别好。
我想知道是否这将是任何更容易使用WPF件的透明度位和它的其余部分(虽然注意Id喜欢移动的整个程序过于WPF这不只是feasable!).我知道旁边没有关于WPF,因此我在这里!什么我是considereing是:
1)主WPF组在它的用户控制,例如例WPF控制:
<UserControl x:Class="WindowsFormsApplication1.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="300" Width="300">
<Grid>
<Rectangle Name="rectangle1" Stroke="White" Fill="Black" RadiusX="10" RadiusY="10" Opacity="0.7" />
<Rectangle Margin="57,101,43,99" Name="dialog" Stroke="Gray" Fill="White" RadiusX="10" RadiusY="10" />
</Grid>
</UserControl>
2)主持它的用户控制(内容)在白色的长方形(对话)的WPF控制。3)允许的内容(它的用户控制)呼码的父WPF的控制。
首先第一件事情...
- 这是一个合理的事情要做,或者我叫了错误的树吗?
- 可这是实现一个更简单时尚?
- 任何人都可以帮我在这里?(样本编码将感激地收到了!)
- 最后...是否有任何在线资源,可以帮助我一)学习WPF和b)变得更加自给自足?
解决方案 2
这里是解决方案我用来解决手头的问题。这个方案依赖于复盖控制,以使其父母作为一位图像。这个,然后被描绘为背景的复盖控制。
public class OverlayingControl : UserControl
{
/// <summary>
/// Overrides the c# standard Paint Background to allow the custom background to be drawn
/// within the OnPaint function
/// </summary>
///
/// <param name="e">Arguements used within this function</param>
protected override void OnPaintBackground( PaintEventArgs e )
{
//Do Nothing
}
protected override void OnPaint( PaintEventArgs e )
{
// Render the Parents image to a Bitmap. NB: bitmap dimensions and Parent Bounds can be changed to achieve the desitred effect
Bitmap background = new Bitmap( Width, Height, PixelFormat.Format64bppArgb );
Parent.DrawToBitmap( background, Parent.Bounds );
// Paint background image
g.DrawImage( background, 0, 0, new RectangleF( Location, Size ), GraphicsUnit.Pixel );
// Perform any alpha-blending here by drawing any desired overlay e.g.
// g.FillRectangle( new SolidBrush( semiTransparentColor ), Bounds);
}
}
这是执行纯粹的内它域,然而我相信这可能是可以通过这个图像来WPF控制呈现为必需的。目前,没有提供用于更新位当父变化,但是,它应该是微不足道,以创造一个定制的方法,清除位和重新绘制Overlayng控制。没有一个优雅的解决方案,我意识到...但看来工作不够好。
其他提示
这当然是可能的,并且我认为你是对的,这将是最简单的方法的工作具有透明度。
我还没有尝试过自己, 但是,根据这条关于演示, 它应该相当简单的。你应该使用 ElementHost控制 主WPF内容。
托管WPF在它控制是一个支持的情况下,一个功能建成的框架。所以应该没有问题,在这样做。还有一个WPF件去其他方式,托管它在WPF应用程序。
不隶属于 StackOverflow