textblock

WPF: Binding Visibility by string contents

廉价感情. 提交于 2019-12-01 13:53:30
问题 Ok, so here is my XAML: <TextBlock Text="{Binding Path=InstanceName}"></TextBlock> If InstanceName is null or an empty string, I want Visibility="Collapsed" . Otherwise I want Visibility="Visible" . How would I do that? 回答1: You could use a ValueConverter: <TextBlock Visibility="{Binding InstanceName, Converter={local:StringNullOrEmptyToVisibilityConverter}}" Text="{Binding InstanceName}"/> with the following codebehind: public class StringNullOrEmptyToVisibilityConverter : System.Windows

How to Display ObservableCollection<string> in a UserControl

与世无争的帅哥 提交于 2019-12-01 13:29:34
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 and copy like I could with a RichTextBox. Does anyone know which control I should use or if there is way

How to increase height limit of the TextBlock control in Windows Phone

♀尐吖头ヾ 提交于 2019-12-01 11:30:56
问题 I need to create a view with multiple TextBlocks populating thousands words. Unfortunately, when I set the Text of the TextBlock to contain a string longer than approx. 2000 characters the later part of the string is not displayed. The size of the TextBlock is still as if it contained all the characters, but the bottom of it is just blank. Do you know what is the constraint that limit the length of the TextBlock? And how can I override it? 回答1: This is a limitation of the TextBox

WPF TextBlock: How to evenly space displayed characters?

偶尔善良 提交于 2019-12-01 07:33:25
I need to display a string with each character displayed every x pixels. (x is accross the whole string). e.g.: "Hello" -> H at position (pixel) 0, e at position 50, l at 100, l at 150, o at 200. Of course I could use a TextBlock for each character but it seems overkill. TranslateTransform doesn't seem to do the trick: It offsets my characters relatively to the END of the previous character, which is not what I want. TIA for your help. Kent Boogaart I don't believe there's an in-built abilty to do this in WPF, but I could be wrong. The code below demonstrates how you could write your own

How to display the text in one line in wpf textblock

女生的网名这么多〃 提交于 2019-12-01 04:12:04
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? Kishore Kumar Use a Converter: <TextBlock Text={Binding Path=TextPropertyName, Converter={StaticResource SingleLineTextConverter}} SingleLineTextConverter.cs: public class SingleLineTextConverter : IValueConverter { public object Convert(object value,

What the best way to get paragraphs in a WPF textblock? (newline chars?)

一笑奈何 提交于 2019-12-01 03:48:30
I have some text which has "\r\n" newline markers. I would like to have the newlines in a WPF textblock. I've tried replacing "\r\n" with "& # 13;" (without the spaces), which worked when I set the Text property in XAML, but doesn't seem to work when setting from the C# code-behind. So...what's the standard way to convert "\r\n" to newlines in a WPF textblock? Ash Try these for a more WPF centric solution. TextBlock.Inlines.Add(new Run("First")); TextBlock.Inlines.Add(new LineBreak()); TextBlock.Inlines.Add(new Run("Second")); See also : XAML based Answer Kent Boogaart textBlock.Text = string

How do I measure the size of a TextBlock in WPF before it is rendered?

╄→гoц情女王★ 提交于 2019-12-01 02:45:09
I have a WPF DataTemplate with two TextBlock controls (stacked) and then some other elements underneath. Due to some complicated layout code, I need to know the height of the two TextBlock elements so that I can draw some fancy connector lines, and line up other controls, etc. If I know the text that's going into the TextBlocks, and I know the font, etc., is there some way I can compute or measure the height of these TextBlocks without actually rendering them? I think it should be sufficient to call the UIElement.Measure(Size) method and subsequently check the UIElement.DesiredSize property.

What the best way to get paragraphs in a WPF textblock? (newline chars?)

淺唱寂寞╮ 提交于 2019-12-01 01:47:18
问题 I have some text which has "\r\n" newline markers. I would like to have the newlines in a WPF textblock. I've tried replacing "\r\n" with "& # 13;" (without the spaces), which worked when I set the Text property in XAML, but doesn't seem to work when setting from the C# code-behind. So...what's the standard way to convert "\r\n" to newlines in a WPF textblock? 回答1: Try these for a more WPF centric solution. TextBlock.Inlines.Add(new Run("First")); TextBlock.Inlines.Add(new LineBreak());

TextBlock text wrapping in GridViewColumn.CellTemplate not working

我的梦境 提交于 2019-11-30 23:13:23
问题 I am having problems getting the TextWrapping to work in this example. Can anyone see what I am duing wrong here? <ListView Name="listViewReportedException" ItemsSource="{Binding ExceptionDetails}"> <ListView.View> <GridView> <GridViewColumn Header="Time" DisplayMemberBinding="{Binding Thrown}" Width="150" /> <GridViewColumn Header="Description" DisplayMemberBinding="{Binding Description}" Width="385"> <GridViewColumn.CellTemplate> <DataTemplate> <TextBlock TextWrapping="Wrap" Text="{Binding}

TextBlock with multiple <Run> spacing

北战南征 提交于 2019-11-30 14:27:37
问题 Given a formatted text block in Windows Phone 7.1 project: <StackPanel Orientation="Horizontal"> <TextBlock Foreground="DarkGray" VerticalAlignment="Bottom" Margin="0,0,0,8"> <Run Text="total length "/> <Run Text="{Binding TotalHours}" FontSize="48"/> <Run Text="h "/> <Run Text=":" FontSize="48"/> <Run Text="{Binding TotalMinutes}" FontSize="48"/> <Run Text="m "/> </TextBlock> </StackPanel> It is being previewed correctly in VS designer: It is already looking not the way I want in Blend: It