static UIElement RenderWithImage(NonnullRichText RichText) { StackPanel lines = new StackPanel(); StackPanel line = new StackPanel(); line.Orientation = Orientation.Horizontal; foreach (object run in RichText.Runs) { if (run is TextLineBreak) { lines.Children.Add(line); line = new StackPanel(); line.Orientation = Orientation.Horizontal; } else { AddTextOrImageToLine(run, line); } } if (line.Children.Count > 0) { lines.Children.Add(line); } return(CompactStack(lines)); }
public void Randomize(Random rand) { NonnullRichText[] options = new NonnullRichText[N_OPTIONS]; bool[] keys = new bool[N_OPTIONS]; int[] originIdx = new int[N_OPTIONS]; List <int> l = new List <int>(); int n = N_OPTIONS; for (int i = 0; i < n; ++i) { l.Add(i); } while (0 < n) { int lidx = rand.Next() % n; int idx = l[lidx]; l.RemoveAt(lidx); --n; options[n] = Options[idx]; keys[n] = Keys[idx]; originIdx[n] = idx; } Options = options; Keys = keys; PermutedOptions = originIdx; }
public static UIElement Render(NonnullRichText RichText) { if (RichText.HasImage()) { return(RenderWithImage(RichText)); } else { return(RenderNoImage(RichText)); } }
public MultiChoiceItem(int DB_ID, NonnullRichText[] cleanData, bool[] keys, bool isDifficult) { ID_in_DB = DB_ID; Stem = cleanData[0]; Options = new NonnullRichText[N_OPTIONS]; Keys = new bool[N_OPTIONS]; PermutedOptions = new int[N_OPTIONS]; for (int i = 0; i < N_OPTIONS; ++i) { Options[i] = cleanData[i + 1]; Keys[i] = keys[i]; PermutedOptions[i] = i; } IsDifficult = isDifficult; }
static UIElement RenderNoImage(NonnullRichText RichText) { StringBuilder text = new StringBuilder(); foreach (object run in RichText.Runs) { string s = run as string; if (s != null) { text.Append(s); } } TextBlock t = new TextBlock(); t.Text = text.ToString(); return(t); }
//TODO: MVC remove public static OptionView NewWith(NonnullRichText richText, int idx, double questionWidth) { OptionView option = new OptionView(); questionWidth -= 10;//alignment StackPanel sp = new StackPanel(); sp.Orientation = Orientation.Horizontal; option.LabelBorder = new Border(); option.LabelBorder.Width = 30; option.LabelBorder.Height = 30; option.LabelBorder.CornerRadius = LabelCornerRadius; option.LabelBorder.Background = Theme.Singleton.DefinedColors[(int)BrushId.Q_BG]; TextBlock tb = new TextBlock(); tb.Text = "" + (char)('A' + idx); tb.Foreground = Theme.Singleton.DefinedColors[(int)BrushId.QID_BG]; tb.VerticalAlignment = VerticalAlignment.Center; tb.HorizontalAlignment = HorizontalAlignment.Center; option.LabelBorder.Child = tb; sp.Children.Add(option.LabelBorder); //TextBlock ansTxt = new TextBlock(); //ansTxt.Text = text; //ansTxt.TextWrapping = TextWrapping.Wrap; //ansTxt.Width = questionWidth - LabelBorder.Width; //ansTxt.VerticalAlignment = VerticalAlignment.Center; //sp.Children.Add(ansTxt); sp.Children.Add(NonnullRichTextView.Render(richText)); option.Content = sp; option.Padding = new Thickness(0); option.Name = "_" + idx.ToString(); //AnsCellLabel = new Label();TODO: MVC remove return(option); }