@@ -55,16 +55,37 @@ void SetListBoxStyle(QuestionnairePresenter questionnairePresenter)
5555
5656 public Tuple < double , double > CalculateFontSizeAndTextWidth ( double width , double fontSize )
5757 {
58- var answers = _questionnairePresenter . CurrentItem . Answers . Values . Select ( x => x . Text ) . ToList ( ) ;
58+ var answers = // All answers for current item
59+ _questionnairePresenter . CurrentItem . Answers . Values
60+ . Select ( x => x . Text )
61+ . ToList ( ) ;
62+
63+ if ( _questionnairePresenter . Questionnaire . Type == QuestionnaireType . ListedAnswers )
64+ answers = // All answers for all items
65+ _questionnairePresenter . Questionnaire . Items
66+ . SelectMany ( item => item . Answers )
67+ . Select ( answer => answer . Value . Text )
68+ . ToList ( ) ;
69+
5970 var maxWidth =
6071 answers
61- . Select ( answer => 1.6 * FontSizeCalculator . GetFontWidth ( answer , answersListBox . FontFamily , fontSize ) )
72+ . Select ( answer => FontSizeCalculator . GetFontWidth ( answer , answersListBox . FontFamily , fontSize ) )
6273 . Max ( ) ;
6374
64- var sum = maxWidth * 1.3 * answers . Count ( ) ;
75+ if ( _questionnairePresenter . Questionnaire . Type == QuestionnaireType . Likert )
76+ maxWidth = 1.6 * maxWidth ;
77+ else
78+ maxWidth = 1.2 * maxWidth ;
79+
80+ var sum = maxWidth * 1.3 ;
81+ if ( _questionnairePresenter . Questionnaire . Type == QuestionnaireType . Likert )
82+ sum = sum * answers . Count ( ) ;
83+ if ( _questionnairePresenter . Questionnaire . Type == QuestionnaireType . ListedAnswers )
84+ sum = sum * 1.5 ;
85+
6586 return sum < width
6687 ? CalculateFontSizeAndTextWidth ( width , fontSize + 0.5 )
67- : Tuple . Create ( fontSize , maxWidth ) ;
88+ : Tuple . Create ( maxWidth , fontSize ) ;
6889 }
6990
7091 void DisplayQuestion ( double width , double height )
@@ -73,8 +94,8 @@ void DisplayQuestion(double width, double height)
7394 return ;
7495
7596 var tuple = CalculateFontSizeAndTextWidth ( width , 1 ) ;
76- var buttonWidth = tuple . Item2 ;
77- var fontSize = tuple . Item1 ;
97+ var checkboxWidth = tuple . Item1 ;
98+ var fontSize = tuple . Item2 ;
7899
79100 itemTextBlock . Text = _questionnairePresenter . CurrentItem . Text ;
80101
@@ -90,20 +111,19 @@ void DisplayQuestion(double width, double height)
90111 answers . Values
91112 . Select ( answer =>
92113 {
93- var textBlock = new TextBlock
94- {
95- Text = answer . ToString ( ) ,
96- FontSize = fontSize ,
97- TextAlignment = TextAlignment . Center
98- } ;
99- var item = new ListBoxItem
114+ var listBoxItem = new ListBoxItem
100115 {
101- Content = textBlock ,
102- Width = buttonWidth ,
116+ Content = new TextBlock
117+ {
118+ Text = answer . ToString ( ) ,
119+ FontSize = fontSize ,
120+ TextAlignment = TextAlignment . Center
121+ } ,
122+ Width = checkboxWidth ,
103123 HorizontalContentAlignment = HorizontalAlignment . Center
104124 } ;
105- _itemsDict . Add ( item , answer ) ;
106- return item ;
125+ _itemsDict . Add ( listBoxItem , answer ) ;
126+ return listBoxItem ;
107127 } ) ;
108128
109129 foreach ( var listBoxItem in items )
0 commit comments