Setting font in light switch textboxes

会有一股神秘感。 提交于 2020-01-06 02:35:26

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!