我制作了一个小型 UWP 应用,它的 NavigationView 有一个设置页面。在其中,我制作了一个 Slider,它允许用户更改页面背景(或基本上是 NavigationView.Background)的亚克力不透明度(TintOpacity)。但我有一个错误
CS0120: An object reference is required for the non-static field, method or property 'MainPage.ChangeAcrylicOpacity(double)'
<!-- MainPage.xaml -->
<NavigationView
x:Name="NavView"
ItemInvoked="NavView_ItemInvoked"
Loaded="NavView_Loaded"> <!-- and some other attributes -->
// MainPage.xaml.cs
public void ChangeAcrylicOpacity(double tintOpacity)
{
AcrylicBrush acrylicBrush = NavView.Background as AcrylicBrush;
acrylicBrush.TintOpacity = tintOpacity;
}
//-----------------------------------------------------------------------------------------------------------------
// Settings.xaml.cs
private void Slider_AcrylicValueChanged(object sender, RangeBaseValueChangedEventArgs e)
{
Slider slider = sender as Slider;
double tintOpacity = slider.Value;
MainPage.ChangeAcrylicOpacity(tintOpacity);
}
错误在Settings.xaml.cs > Slider_AcrylicValueChanged > MainPage.ChangeAcrylicOpacity(tintOpacity);
当我MainPage.xaml.cs > ChangeAcrylicOpacity(double tintOpacity)
从更改public
为时出现此错误private
,但出现错误'MainPage.ChangeAcrylicOpacity(double)' is inaccessible due to its protection level
请提出一些方法来在不同的页面上使用一个页面的功能而不会出错。注意:我已经搜索了互联网,但没有网站解决我的问题(包括 StackOverflow)。