Q:

Notepad in WPF, System.IO.File.ReadAllText

Have troubles with opening a textfile...
Have this code, there are empty stringFromFile after called
    public string OpenTextFile ()
    {
        var stringFromFile = string.Empty;
        OpenFileDialog ofd = new OpenFileDialog();
        if (ofd.ShowDialog().ToString().Equals("OK"))
            stringFromFile = System.IO.File.ReadAllText(ofd.FileName);
        return stringFromFile;
    }

A:

In WPF OpenFileDialog.ShowDialog()return a Nullable<bool> so you should change the code as follow
public string OpenTextFile()
        {
            OpenFileDialog ofd = new OpenFileDialog();
            Nullable<bool> res = ofd.ShowDialog();
            if(res == true)
            {
                using(StreamReader sr = new StreamReader(ofd.FileName))
                {
                  return sr.ReadToEnd();
                }
            }
            //Here message error
            throw new Exception("Something");
        }

A:

Calling ToString() is not needed and worse, it would throw a NullReferenceException if the return value of ShowDialog() is null because ShowDialog() returns bool? (Nullable<bool>) as pointed out by the other answer. 
Here's a two line solution...
string OpenTextFile()
{
    var ofd = new OpenFileDialog();
    return ofd.ShowDialog() == true ?
            System.IO.File.ReadAllText(ofd.FileName) :
            String.Empty;
}

