申し訳ありませんが、私は多くの基本的な問題にぶつかる運があります。私はこの特定の問題を回避する方法を考え出すことはできません。新しく作成されたオブジェクトの保護レベルを変更しますか?
このコードは、 "MainWindow"クラスで作成されたオブジェクトの "_Player.Name"プロパティにアクセスする必要があります。
編集:今度はコード全体を入れます。文字列のあるCode_Behindは次のとおりです。
public class Code_Behind
{
private static string _Name = "Default";
public class Player
{
public void setName(string name) //Ignore this part, was trying to find a work around here
{
_Name = name;
}
public string Name
{
get { return _Name; }
set
{
_Name = value;
}
}
}
//contentControl is used to store Content properties
//UI elements are bound to Content properties to efficiently change their Content
public class contentControl : INotifyPropertyChanged
{
protected void OnPropertyChanged(string name)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
public void setEvent(string Event)
{
textBoxContent = Event;
}
public void addEvent(string Event)
{
textBoxContent +="\n" + Event;
}
public class Events
{
public string EV001 = String.Format("\"Greetings {0}. What can I do for you today?\"", window.PlayerName);
}
}
そして、ここでメインウィンドウです:
public partial class MainWindow : Window
{
Code_Behind.contentControl cC = new Code_Behind.contentControl();
Code_Behind.contentControl.Events Events = new Code_Behind.contentControl.Events();
Code_Behind.Player _Player = new Code_Behind.Player();
public string GetPlayerName()
{
return _Player.Name;
}
public static string _name = "null";
public MainWindow()
{
this.DataContext = cC;
InitializeComponent();
}
'' 'public Code_Behind.Player _Player = new Code_Behind.Player();' ''? – tym32167
'EV001'は良いメンバー名ではありません。もっと読みやすく、自己記述的なものを考えてみましょう。 – Dai
オブジェクトに保護レベルがないため、オブジェクトの保護レベルを変更することはできません。フィールドと変数は行います。 tym32167には1つの答えがあります。 mybirthnameのほうが優れています。私のほうが最善です: 'public String PlayerName {get {return _Player.Name; }} ' –