如何解决如何在WPF中通过单击按钮设置父窗口的属性
我对WPF还是很陌生,所以我真的不知道如何表达自己:
我有一个“ Window.xaml”,它在一个框架中托管了另一个窗口“ ReportGenerator.xaml”:
<Metro:MetroWindow x:Class="ROGERS.Windows.Window"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:ROGERS.Windows"
xmlns:ViewModels="clr-namespace:ROGERS.Windows.ViewModels"
xmlns:Views="clr-namespace:ROGERS.Windows.Views"
xmlns:Metro="http://metro.mahapps.com/winfx/xaml/controls"
xmlns:MetroIcons="http://metro.mahapps.com/winfx/xaml/iconpacks"
mc:Ignorable="d"
Title="ROGERS"
TitleAlignment="Center"
Icon="App.ico"
IconBitmapScalingMode="HighQuality"
Height="800"
Width="1440"
ShowIconOnTitleBar="True"
WindowStartupLocation="CenterScreen"
WindowTitleBrush= "#0c3868"
BorderBrush="#0c3868"
BorderThickness="1,1,1">
<Metro:MetroWindow.DataContext>
<ViewModels:WindowViewModel />
</Metro:MetroWindow.DataContext>
<Frame Source="Views/ReportGenerator.xaml"/>
</Metro:MetroWindow>
我想通过按下“ ReportGenerator.xaml”中使用的按钮来设置“ Window.xaml”(父级)的不透明度。基本上,在相应的“ ReportGenerator.xaml.cs”中,我想按照Window.Opacity = 0.25
之类的方式进行操作。但是我不知道如何访问Window.xaml的不透明度属性。
有没有办法做到这一点?
解决方法
尝试此代码
Window yourParentWindow = (Window)MetroWindow.GetWindow(this);
yourParentWindow.Opacity = 0.25;
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。