【发布时间】:2020-03-24 01:20:06
【问题描述】:
当装饰器放置在 Windows 10 用户控件上时,我试图“模糊”它。
更准确地说,我在 wpf 用户窗口中有一个 datagrid 控件。 When a cell in the datagrid is selected, an editing adorner is created over the datagrid control.
public DataGridAnnotationAdorner(DataGrid adornedDataGrid, IVisit visit, DateTime TableDate)
: base(adornedDataGrid)
{
Control = new DataGridAnnotationControl(visit, TableDate);
AddLogicalChild(Control);
AddVisualChild(Control);
Loaded += DataGridAnnotationAdorner_Loaded;
}
private void DataGridAnnotationAdorner_Loaded(object sender, RoutedEventArgs e)
{
EnableBlur(AdornedElement);
}
加载的事件然后调用(一个非常标准的)模糊/玻璃效果方法:
internal void EnableBlur(UIElement dataGrid)
{
HwndSource source = (HwndSource)PresentationSource.FromVisual(dataGrid);
IntPtr hwnd = source.Handle;
var accent = new AccentPolicy();
accent.AccentState = AccentState.ACCENT_ENABLE_BLURBEHIND;
var accentStructSize = Marshal.SizeOf(accent);
var accentPtr = Marshal.AllocHGlobal(accentStructSize);
Marshal.StructureToPtr(accent, accentPtr, false);
var data = new WindowCompositionAttributeData();
data.Attribute = WindowCompositionAttribute.WCA_ACCENT_POLICY;
data.SizeOfData = accentStructSize;
data.Data = accentPtr;
SetWindowCompositionAttribute(hwnd, ref data);
Marshal.FreeHGlobal(accentPtr);
}
没有错误报告....但是不起作用。
那么,如何给装饰器下的控件赋予“玻璃”外观?
TIA
【问题讨论】:
-
希望您不介意我发布您刚刚删除的问题,但我正要对此发表评论以防万一:可能重复Delete parent if it's not referenced by any other child PS我不知道锁定解决方案是否是基于有保证的行为,或者回答者只是不合理地假设实现。
标签: c# wpf aero-glass