次のように、プロパティWindows Forms
を使用してアプリケーションを半透明にすることができます。Opacity
WPFで同じ結果を達成しようとしていますが、不可能に見えます。を変更するOpacity
とMainWindow
、コンテンツが暗くなった同じウィンドウが表示されます。AllowTransparency
どうにかしてフレームを再構築する必要があり、複雑すぎるソリューションのように見えるため、使用すると多くの問題が生じます。次のアプローチも試しました。
protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
m_Handle = (new WindowInteropHelper(this)).Handle;
if (Properties.Settings.Default.Transparency)
NativeMethods.MakeWindowTransparent(m_Handle);
}
internal static void MakeWindowTransparent(IntPtr windowHandle)
{
if (Environment.Is64BitProcess)
{
Int32 extendedStyle = GetWindowLong64(windowHandle, WindowLongIndex.ExtendedStyle).ToInt32();
SetWindowLong64(windowHandle, WindowLongIndex.ExtendedStyle, (new IntPtr(extendedStyle | 0x00000020)));
}
else
{
Int32 extendedStyle = GetWindowLong32(windowHandle, WindowLongIndex.ExtendedStyle);
SetWindowLong32(windowHandle, WindowLongIndex.ExtendedStyle, (extendedStyle | 0x00000020));
}
}
まあ、どちらもうまくいきません。真剣に、なぜそのような制限があるのですか?回避策はありますか?