UserControl 元素由于其保护级别而无法访问
UserControl element inaccessible due to its protection level
我正在编写 Windows Phone 8.1 应用程序 (WinRT)。
我的用户控件:
XAML:
<UserControl x:Name="LoadingProgressBarPage"
x:Class="Project1.Custom.General.UserControls.LoadingOverlayFullScreen"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Merakyahoga.com.Custom.General.UserControls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
Foreground="{x:Null}"
d:DesignHeight="800" d:DesignWidth="480" >
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<StackPanel
Name="LayoutRoot_StackPanelMain"
Grid.Row="1"
Orientation="Vertical">
<ProgressBar Name="ProgressBar"
IsIndeterminate="True"
Foreground="{StaticResource DefaultTheme_DarkBlueColor}"
Height="50"
Width="480"
VerticalAlignment="Center"/>
<StackPanel Name="LayoutRoot_SubStackPanel"
Orientation="Horizontal"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<Image Name="ImageHolder_Main"
Width="54">
</Image>
<TextBlock Name="ProgressBarText"
Text="Please Wait.."
Margin="10,0,0,0"
FontWeight="Normal"
HorizontalAlignment="Center"
FontSize="18"
Foreground="{StaticResource DefaultTheme_DarkBlueColor}" VerticalAlignment="Center"/>
</StackPanel>
</StackPanel>
</Grid>
cs:
namespace Project1.Custom.General.UserControls
{
public partial class LoadingOverlayFullScreen : UserControl
{
public LoadingOverlayFullScreen()
{
InitializeComponent()
//WINRT:
this.LayoutRoot.Height = Window.Current.Bounds.Height;
this.LayoutRoot.Width = Window.Current.Bounds.Width;
}
}
}
在我的mainpage.cs:
LoadingOverlayFullScreen LoadingOverlayFullScreenObject = new LoadingOverlayFullScreen();
//test:
LoadingOverlayFullScreenObject.ProgressBarText = "Hello"; //ERROR Here >> **element inaccessible due to its protection level**
通过命名 TextBlock
元素,您可以使 XAML 编译器生成具有该名称的 class 成员,即 ProgressBarText
。但是该成员的可访问性不是 public
,而是 internal
。
如果您确实希望该字段为 public
,您可以添加 x:FieldModifier
属性:
<TextBlock Name="ProgressBarText"
x:FieldModifier="public"
Text="Please Wait.."
Margin="10,0,0,0"
FontWeight="Normal"
HorizontalAlignment="Center"
FontSize="18"
Foreground="{StaticResource DefaultTheme_DarkBlueColor}"
VerticalAlignment="Center"/>
也就是说,最好在代码隐藏中将 TextBlock
对象的 Text
属性 公开为 string
属性 .或者更好的是,使用数据绑定来控制 TextBlock
的 Text
值(但是您的代码示例不够完整,我无法说出您将如何做到这一点)。
我正在编写 Windows Phone 8.1 应用程序 (WinRT)。
我的用户控件: XAML:
<UserControl x:Name="LoadingProgressBarPage"
x:Class="Project1.Custom.General.UserControls.LoadingOverlayFullScreen"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Merakyahoga.com.Custom.General.UserControls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
Foreground="{x:Null}"
d:DesignHeight="800" d:DesignWidth="480" >
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<StackPanel
Name="LayoutRoot_StackPanelMain"
Grid.Row="1"
Orientation="Vertical">
<ProgressBar Name="ProgressBar"
IsIndeterminate="True"
Foreground="{StaticResource DefaultTheme_DarkBlueColor}"
Height="50"
Width="480"
VerticalAlignment="Center"/>
<StackPanel Name="LayoutRoot_SubStackPanel"
Orientation="Horizontal"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<Image Name="ImageHolder_Main"
Width="54">
</Image>
<TextBlock Name="ProgressBarText"
Text="Please Wait.."
Margin="10,0,0,0"
FontWeight="Normal"
HorizontalAlignment="Center"
FontSize="18"
Foreground="{StaticResource DefaultTheme_DarkBlueColor}" VerticalAlignment="Center"/>
</StackPanel>
</StackPanel>
</Grid>
cs:
namespace Project1.Custom.General.UserControls
{
public partial class LoadingOverlayFullScreen : UserControl
{
public LoadingOverlayFullScreen()
{
InitializeComponent()
//WINRT:
this.LayoutRoot.Height = Window.Current.Bounds.Height;
this.LayoutRoot.Width = Window.Current.Bounds.Width;
}
}
}
在我的mainpage.cs:
LoadingOverlayFullScreen LoadingOverlayFullScreenObject = new LoadingOverlayFullScreen();
//test:
LoadingOverlayFullScreenObject.ProgressBarText = "Hello"; //ERROR Here >> **element inaccessible due to its protection level**
通过命名 TextBlock
元素,您可以使 XAML 编译器生成具有该名称的 class 成员,即 ProgressBarText
。但是该成员的可访问性不是 public
,而是 internal
。
如果您确实希望该字段为 public
,您可以添加 x:FieldModifier
属性:
<TextBlock Name="ProgressBarText"
x:FieldModifier="public"
Text="Please Wait.."
Margin="10,0,0,0"
FontWeight="Normal"
HorizontalAlignment="Center"
FontSize="18"
Foreground="{StaticResource DefaultTheme_DarkBlueColor}"
VerticalAlignment="Center"/>
也就是说,最好在代码隐藏中将 TextBlock
对象的 Text
属性 公开为 string
属性 .或者更好的是,使用数据绑定来控制 TextBlock
的 Text
值(但是您的代码示例不够完整,我无法说出您将如何做到这一点)。