[英]Bring Usercontrol to front making background transparent
在下面的圖像中,我將圖像的背景內容作為用戶控件,將前圓作為用戶控件。 當在背景用戶控件中單擊一個按鈕時,那么我需要通過將圓圈UserControl置於最前面並模糊背景來顯示它,如下圖所示。 現在,在ViewModel的第一個UserControl中,我有一個命令,並且正在執行類似的操作。 問題是窗口沒有出現在前面,我無法模糊背景。 請幫忙。
private void OpenWidget(object obj)
{
WidgetWindow window = new WidgetWindow();
window.WindowState = WindowState.Maximized;
window.WindowStyle = WindowStyle.None;
window.Show();
window.BringIntoView();
}
我會改用Window,所以像這樣:
<Window x:Class="YourNamespace.WidgetWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="WidgetWindow"
WindowStyle="None" ResizeMode="NoResize" WindowStartupLocation="CenterScreen" WindowState="Maximized"
AllowsTransparency="True" Background="#80000000">
<Grid>
<Ellipse Width="300" Height="300" Fill="CornflowerBlue" />
</Grid>
</Window>
然后在按鈕處理程序中執行ShowDialog()
並將主窗口的效果設置為模糊:
private void Button_Click(object sender, RoutedEventArgs e)
{
this.Effect = new BlurEffect();
var dlg = new WidgetWindow();
dlg.Owner = this;
dlg.ShowDialog();
this.Effect = null;
}
結果:
顯然,您需要對此進行調整以適應您的特定要求,例如,如果您不希望它全屏顯示,請使用UserControl;如果您需要無模式,請使用Show()
而不是ShowDialog()
,但這應該足以實現你開始了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.