For example, as in the picture. So that when you click on the button above the selected element (or group of elements) there appears a negation sign (double / triple). If it cannot be implemented in these languages, then there may be at least some other ideas ..
1 answer
Well, you can do it, although it is much less convenient than in TeX. You will have to measure characters yourself and work with font properties. Here you have a simple option: it does not take into account italics and lowercase letters.
XAML:
<Window x:Class="Test.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Π’Π΅ΡΡ" Height="350" Width="525" TextBlock.FontSize="15"> <Grid> <Grid HorizontalAlignment="Center" VerticalAlignment="Center" x:Name="Host" ClipToBounds="False"> <TextBlock x:Name="Target"/> </Grid> </Grid> </Window> Let's start a small auxiliary class:
class LevelDescriptor { public double Y; public List<(double from, double to)> Lines; } Our code:
string text = "(X & Y) & (X & Y) & (X & Z)"; // ΠΎΠΏΠΈΡΠ°Π½ΠΈΠ΅ Π»ΠΈΠ½ΠΈΠΉ var lines = new List<List<(int from, int to)>>() { new List<(int from, int to)>() { (1, 2), (15, 16), (25, 26) }, // ΡΡΠΎΠ²Π΅Π½Ρ 1 new List<(int from, int to)>() { (1, 6), (11, 16), (21, 26) }, // ΡΡΠΎΠ²Π΅Π½Ρ 2 new List<(int from, int to)>() { (0, 27) }, // ΡΡΠΎΠ²Π΅Π½Ρ 3 }; // Π²Π΅ΡΡΠΈΠΊΠ°Π»ΡΠ½ΠΎΠ΅ ΡΠ°ΡΡΡΠΎΡΠ½ΠΈΠ΅ ΠΌΠ΅ΠΆΠ΄Ρ Π»ΠΈΠ½ΠΈΡΠΌΠΈ const double vgap = 4; // ΡΠ°Π·ΡΠ΅ΡΠ΅Π½ΠΈΠ΅ Π²Π°ΡΠ΅Π³ΠΎ ΠΌΠΎΠ½ΠΈΡΠΎΡΠ°. (Π΅ΡΠ»ΠΈ ΠΎΠ½ΠΎ ΠΈΠ·ΠΌΠ΅Π½ΡΠ΅ΡΡΡ, Π½Π°ΠΏΡΠΈΠΌΠ΅Ρ, Ρ Π²Π°Ρ ΠΈΡ
Π½Π΅ΡΠΊΠΎΠ»ΡΠΊΠΎ, ΡΠΎ // Π½Π°Π΄ΠΎ ΠΏΠΎΠ΄ΠΏΠΈΡΠ°ΡΡΡΡ Π½Π° Π΅Π³ΠΎ ΠΈΠ·ΠΌΠ΅Π½Π΅Π½ΠΈΠ΅) var pixelsPerDip = VisualTreeHelper.GetDpi(this).PixelsPerDip; // ΠΊΡΠ΄Π° ΠΏΠΈΡΠ΅ΠΌ TextBlock tb = Target; tb.Text = text; // ΠΎΡΠ±ΠΈΡΠ°Π΅ΠΌ Ρ ΡΠ΅ΠΊΡΡΠ±ΠΎΠΊΡΠ° ΡΡΠΈΡΡ var font = new Typeface(tb.FontFamily, tb.FontStyle, tb.FontWeight, tb.FontStretch); // ΡΠΎΡΠΌΠ°ΡΠΈΡΡΠ΅ΠΌ ΡΠ΅ΠΊΡΡ FormattedText formattedText = new FormattedText( text, CultureInfo.GetCultureInfo("en-US"), FlowDirection.LeftToRight, font, tb.FontSize, Brushes.Black, // ΠΊΠΎΠ½ΠΊΡΠ΅ΡΠ½Π°Ρ ΠΊΠΈΡΡΡ Π½Π°ΠΌ Π½Π΅ Π²Π°ΠΆΠ½Π°, ΠΌΡ ΠΈΡΠΏΠΎΠ»ΡΠ·ΡΠ΅ΠΌ ΡΠΎΠ»ΡΠΊΠΎ Π³Π΅ΠΎΠΌΠ΅ΡΡΠΈΡ pixelsPerDip); // Π½Π° ΠΊΠ°ΠΊΠΎΠΉ Π²ΡΡΠΎΡΠ΅ Π½Π°ΡΠΈΠ½Π°Π΅ΡΡΡ Π±ΠΎΠ»ΡΡΠ°Ρ Π±ΡΠΊΠ²Π°? double vstart = formattedText.Baseline - font.CapsHeight * tb.FontSize; // ΠΎΠΏΠΈΡΠ°ΡΠ΅Π»ΠΈ Π»ΠΈΠ½ΠΈΠΉ List<LevelDescriptor> result = new List<LevelDescriptor>(); // ΡΠ΅ΠΊΡΡΠ°Ρ Π²ΡΡΠΎΡΠ° double height = vstart; foreach (var line in lines) { // ΠΏΠΎΠ»ΡΡΠ°Π΅ΠΌ ΠΎΠΊΡΡΠΆΠ°ΡΡΠΈΠ΅ ΠΏΡΡΠΌΠΎΡΠ³ΠΎΠ»ΡΠ½ΠΈΠΊΠΈ Π΄Π»Ρ Π²ΡΠ΅Ρ
ΠΏΠΎΠ΄ΡΡΡΠΎΠΊ var boundingBoxes = line.Select(d => formattedText.BuildHighlightGeometry(new Point(), d.from, d.to - d.from).Bounds); height -= vgap; // Π·Π°ΠΏΠΎΠΌΠ½ΠΈΠ»ΠΈ Π²ΡΡΠΎΡΡ, ΠΈ Π»Π΅Π²ΡΡ/ΠΏΡΠ°Π²ΡΡ Π³ΡΠ°Π½ΠΈΡΡ Π΄Π»Ρ ΠΊΠ°ΠΆΠ΄ΠΎΠ³ΠΎ ΠΎΡΡΠ΅Π·ΠΊΠ° result.Add(new LevelDescriptor() { Y = height, Lines = boundingBoxes.Select(bb => (from: bb.Left, to: bb.Right)).ToList() }); } // ΡΠ΅ΠΏΠ΅ΡΡ ΡΠΎΠ·Π΄Π°ΡΠΌ Π»ΠΈΠ½ΠΈΠΈ var brush = tb.Foreground; // ΡΠ²Π΅Ρ ΡΠ°ΠΊΠΎΠΉ ΠΆΠ΅, ΠΊΠ°ΠΊ ΠΈ Ρ ΡΡΡΠΎΠΊΠΈ foreach (var level in result) { foreach (var d in level.Lines) Host.Children.Add( new Line() { X1 = d.from, X2 = d.to, Y1 = level.Y, Y2 = level.Y, StrokeThickness = 1, // ΡΠΎΠ»ΡΠΈΠ½Π° Stroke = brush, Fill = brush }); } That's all. You will have to build your own lines table based on your data.
I got this result here:
- Can you please still help: how to put a negative on the selected text, for example, by pressing a button? If possible, show this code? - Anastasia
- @ Anastasia: But this is more difficult. If you need to display not in
TextBlock'e, but inTextBox' e (you can only select text there), my code will not work. Plus, you will have to get the indices of the selected elements (this is simple), and check them for meaningfulness, for example, so that the line does not end in the middle of the formula (this is difficult). - VladD - and other options, where and how to implement it exist? - Anastasia
- @ Anastasia: Well, hmm. It depends on what you need. Where exactly are you going to show the text? In
TextBox'e? InTextBlock'e? Somewhere else? - VladD - I want to Textbox. - Anastasia
|


\overline. Association: stackoverflow.com/q/8899204/6766879 - Andrew NOP