How to Disable DropShadow or any shadow of ContentDialog? UWP, XAML

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-23 20:15:06

问题


I am using ContentDialog with a custom xaml style for it, the contentDialog is supposed to have rounded corners but I can see rectangular shadow... interestingly the shadow doesn't show in Windows 1809 build, it does in 1903.

I have seen that when I remove the "Container" border, the shadow goes away but the content dialog is no longer in the center of the page ,it goes to top left.

I also tried using the Shadow property, and tried wrapping the code in DropShadow..it does not make the shadow go away.

How can I disable or turn off the shadow from the content dialog ? Or, how can I make the Shadow get rounded... the shadow stays...Please help.


回答1:


In the default style for a content dialog there is an element named "BackgroundElement", it is a Border element, changing it to Grid will remove the shadow as the shadow is applied on the Border element.

However, doing this will mess up the positioning of the Content dialog, as apparently UWP framework positions/repositions the content dialog with respect to the named element which is supposed to be a border. But, with grid and a bit of a nasty hack, we can fix it, we could grab the reference of the Content dialog (at a suitable position), and set it's Margin like this (only by setting the margin can we really move/reposition the ContentDialog: this bit of knowledge comes from a lot of trial and error). Here's the repositioning code using margin.. that has been working

   double leftmargin = (Window.Current.Bounds.Width / 2.0) - (contentDialogReference.ActualWidth / 2.0);
   double topmargin = (Window.Current.Bounds.Height / 2.0) - (contentDialogReference.ActualHeight / 2.0);
   contentDialogReference.Margin = new Thickness(leftmargin, topmargin, 0, 0);


来源:https://stackoverflow.com/questions/57217007/how-to-disable-dropshadow-or-any-shadow-of-contentdialog-uwp-xaml

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!