textblock

WPF: Cutting the part of the last letter in textblock when FontStyle is Oblique

狂风中的少年 提交于 2020-01-06 04:28:15
问题 I have a simple XAML example: <Grid> <Button x:Name="button1" FontSize="28" FontWeight="Bold" FontStyle="Oblique" HorizontalContentAlignment="Center" Margin="296,142,296,249"> <TextBlock Width="Auto" Text="button" Padding="0" VerticalAlignment="Center"/> </Button> <Button x:Name="button2" Content="button" FontSize="28" FontWeight="Bold" FontStyle="Oblique" Margin="296,234,282,146" /> </Grid> If height of any button will changed in design mode (or added and changed property Height in xaml),

WPF How to arrange TextBlock with different Fontsize at bottomline

和自甴很熟 提交于 2020-01-03 19:57:36
问题 today i hit a really annoing problem with wpf. i just want to align Textblock controls(with different fontsize) at the bottom line. <StackPanel Grid.Row="0" Orientation="Horizontal"> <TextBlock Text="ABC" FontSize="12" VerticalAlignment="Bottom"/> <TextBlock Text="QWERT" FontSize="24" VerticalAlignment="Bottom"/> <TextBlock Text="XYZ" FontSize="18" VerticalAlignment="Bottom"/> </StackPanel> what do i miss? 回答1: found a workaround. i have to use Run inside my TextBlock <StackPanel Grid.Row="0"

TextBlock: Binding of Text and StringFormat

坚强是说给别人听的谎言 提交于 2020-01-03 17:17:33
问题 Is it possible to bind Text and StringFormat too? <TextBlock Text="{Binding Path=Price, StringFormat={Binding Path=DecimalPoints}}" /> DecimalPoints is constantly changing from F0 to F15 . Unfortunatelly the code above doesn't compile. 回答1: I think your best bet is definitely a converter. Then your binding would look like this: <TextBlock.Text> <MultiBinding Converter="{StaticResource StringFormatConverter }"> <Binding Path="Price"/> <Binding Path="DecimalPoints"/> </MultiBinding> </TextBlock

WPF- “LineSpacing” in a TextBlock

做~自己de王妃 提交于 2020-01-02 05:43:07
问题 I have a TextBlock I would like to pass a property of ' LineSpacing '. The thing with using " LineHeight " with LineStackingStrategy="BlockLineHeight" is that it also applies the LineHeight to the segment before the first line: How can I manage to preserve said ' LineSpacing ' without modifying the LineHeight before the first line? One thing I though might work is to separate each line in a Paragraph of a FlowDocument , since the Paragraph has a property Spacing Before Line and Spacing After

WPF TextBlock Negative Number In Red

我的梦境 提交于 2020-01-02 02:42:08
问题 I am trying to figure out the best way to create a style/trigger to set foreground to Red, when value is < 0. what is the best way to do this? I'm assuming DataTrigger, but how can I check for negative value, do i have to create my own IValueConverter? 回答1: If you are not using an MVVM model (where you may have a ForegroundColor property), then the easiest thing to do is to create a new IValueConverter, binding your background to your value. In MyWindow.xaml: <Window ... xmlns:local="clr

Bind WPF TextBlock to text file

白昼怎懂夜的黑 提交于 2019-12-31 04:10:19
问题 How can I bind a WPF TextBlock to a text file? I want for the TextBlock to display the content of the file. 回答1: You need to read the file into a string in memory and bind to that string instead. View model: class ViewModel { public string FileText { get; set; } public void ReadFile(string path) { FileText = File.ReadAllText(path); } } XAML: <TextBlock Text="{Binding FileText}"/> 回答2: If you want the text to be formatted my inline markup you could look at the sub-class of TextBlock I made

Read C# Textblock Text Property filled using Inlines

只愿长相守 提交于 2019-12-31 03:04:29
问题 Let us say that I have an empty Textblock : textblock1.Text = ""; Then I only put Inlines content in it with these two statements: textblock1.Inlines.Add(new Run() { Text = "A. ", Foreground = Brushes.Red }); textblock1.Inlines.Add(new Run() { Text = responses.Current.Value, Foreground = Brushes.Black}); The amazing stuff is that I can visualize the content properly in my window, however the Text property of the Textblock keeps being empty! This causes a problem because I need to pass the

How to Display ObservableCollection<string> in a UserControl

末鹿安然 提交于 2019-12-30 11:12:43
问题 I'm new to WPF and I've found some similar questions but can't quite figure out the last part. I have a ViewModel with an ObservableCollection that contains error messages. I want to display these on the form AND allow the user to select and copy all or part of the messages. (In the past in WinForm apps I used a RichTextBox for this, but I can't figure out how to bind to one to the collection in WPF.) I got the look I was after with the following xaml, but there is no built-in way to select

How to display the text in one line in wpf textblock

我的未来我决定 提交于 2019-12-30 08:36:39
问题 I'm a newbie with wpf , what i want to display the text in one line in wpf textblock. eg.: <TextBlock Text ="asfasfasfa asdasdasd" </TextBlock> TextBlock display it in two lines default, but i want it in only one line like this"asafsf asfafaf". I mean show all the text in one line even there are more than one lines in the text what should i do? 回答1: Use a Converter: <TextBlock Text={Binding Path=TextPropertyName, Converter={StaticResource SingleLineTextConverter}} SingleLineTextConverter.cs:

Display images in TextBlock (WPF)

一个人想着一个人 提交于 2019-12-30 03:04:15
问题 I'm working on a simple chat application. Currently the messages are binded to a custom-styled listbox like this (simplified XAML): <ListBox ItemsSource="{Binding MessageCollection}"> <ListBox.ItemTemplate> <DataTemplate> <TextBlock Text="{Binding Text}"/> </DataTemplate> </ListBox.ItemTemplate> </ListBox> Now I would like to be able to put images (like graphical smileys) into the displayed message text. Is there any way to achieve this using TextBlock (or any other standart component) or do