c# - 如何更改 Xamarin Studio 中 GUI 设计器生成的字段的访问级别

标签 c# mono xamarin-studio gtk# access-levels

我正在使用 Xamarin Studio 在 Gtk# 中编写我的代码。 当我在其中创建一个新窗口和一个 TreeView 时,访问级别将是私有(private)的。我想在其他类中使用它 (TreeView),所以我想将访问级别更改为内部,但我找不到如何做到这一点。 感谢您提前提供帮助。 这是我想由 GUI 设计者更改的代码(不是写入代码内部,因为它会被 GUI 设计者覆盖...)

    // This file has been generated by the GUI designer. Do not modify.
namespace XX_xxxx
{
    public partial class Settings
    {
        private global::Gtk.VBox vbox1;

        private global::Gtk.ScrolledWindow GtkScrolledWindow;

        private global::Gtk.TreeView settingsTreeView;

        private global::Gtk.HBox hbox1;

        private global::Gtk.ToggleButton saveAndCloseButton;

        private global::Gtk.ToggleButton closeButton;

        protected virtual void Build ()
        {

这是我想使用的地方(在我使用 Settings 类实例的其他类中): settings.settingsTreeView.Model = settingsListStore;

错误信息是:

Error CS0122: `XX_xxxxx.Settings.settingsTreeView' is inaccessible 
    due to its protection level (CS0122) (XX_xxxx_GUI)

最佳答案

我在 Xamarin 论坛上得到了这个答案:

The supported way of doing this is to remove the property from the .designer.cs file and place it in the main .cs file. Then remove the [DesignerGenerated] attribute from the declaration.

The code generation in the designer will recognise that the [Outlet] exists in the actual .cs file and will not place one in the .designer.cs file. Once you do this, you can add the public/internal modifiers as you want.

关于c# - 如何更改 Xamarin Studio 中 GUI 设计器生成的字段的访问级别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29369760/

相关文章:

c# - ComboBox 绑定(bind)中断对 SelectedItem 中对象的更改

f# - 一般而言,F# 和 MonoDevelop 的 F# 插件是否为 Linux 维护?

xamarin - 未找到嵌入资源

ios - 面向 ios 7 但支持 ios 5+ monotouch

c# - 带有 MonoTouch RELEASE 版本的 SQLite - 无法获得 PK?

c# - 在 android 项目中引用 F# 代码

c# - 在c#中打印xml节点列表

c# - 通过 UDP 到 C# 的 IPFIX 数据 - 我可以解码数据吗?

javascript - .html 文件是否可以识别 .NET scriptlet 还是必须将其转换为 aspx

c# - DateTime.Now.Tostring() - 奇怪的结果