问题
I am trying to set set the font of a TextBox in LightSwitch. I am not sure if there is a problem with my code, or if this just isn't possible.
The code executes, and I have stepped through it to make sure it executes, and all code is reached and executed, but there is not change to the controls on the screen.
My code is:
private void SetMono(string controlName)
        {
            var ctrl = this.FindControl(controlName);
            if (ctrl != null)
            {
                ctrl.ControlAvailable += (s, e) =>
                {
                    if (e.Control is TextBox)  // I put break point here to test.                        {
                        var tb = (TextBox)e.Control;
                        var ff = new System.Windows.Media.FontFamily("courierNew,courier,monospace");
                        tb.FontFamily = ff;
                    }
                };
            }
        }
Am I doing something wrong?
(I am using VS 2013)
回答1:
The problem was my FontFamily.
I could not find to much information on how the Font Family should be named, but "Consolas" did work.
Final Code:
private void SetMono(string controlName)
        {
            var ctrl = this.FindControl(controlName);
            if (ctrl != null)
            {
                ctrl.ControlAvailable += (s, e) =>
                {
                    if (e.Control is TextBox)
                    {
                        var tb = (TextBox)e.Control;
                        tb.FontFamily = new System.Windows.Media.FontFamily("Consolas");
                    }
                };
            }
        }
来源:https://stackoverflow.com/questions/24179502/setting-font-in-light-switch-textboxes