问题
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