textblock

Wpf Binding Stringformat to show only first character

纵然是瞬间 提交于 2019-12-18 07:06:46
问题 Is there any way so that i can show only first character of a Bound string on a textblock..? For eg;If i Bind 'Male', my textblock should only show 'M'..... 回答1: You might use a value converter to return a string prefix: class PrefixValueConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { string s = value.ToString(); int prefixLength; if (!int.TryParse(parameter.ToString(), out prefixLength) || s

Align bottoms of text in controls

时光毁灭记忆、已成空白 提交于 2019-12-17 18:49:26
问题 The following snippet: <Window x:Class="Window1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> <Grid> <StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center"> <Label Content="Name:"/> <Label Content="Itzhak Perlman" FontSize="44"/> </StackPanel> </Grid> </Window> Renders the following: Is there any way I can set in the Labels' styles so that their text bottoms should be aligned? I

How to remove additional padding from a WPF TextBlock?

ぐ巨炮叔叔 提交于 2019-12-17 15:54:25
问题 By default a WPF TextBlock seems to have additional top and bottom padding applied. I wish this wasn't so. I've tried setting negative padding, but got an exception: 0,-10,0,0' is not a valid value for property 'Padding'. I've tried setting the LineHeight property, to no apparent effect. This is how the TextBlock looks in Blend. I've marked the problematic portion with maroon red. 回答1: Some research and H.B. guided me to the right answer, which is setting the following properties: <TextBlock

WPF TextBlock highlight certain parts based on search condition

回眸只為那壹抹淺笑 提交于 2019-12-17 10:56:48
问题 I have TextBlock that has Inlines dynamicly added to it (basically bunch of Run objects that are either italic or bold). In my application I have search function. I want to be able to highlight TextBlock's text that is in being searched for. By highlighting I mean changing certain parts of TextBlock text's color (keeping in mind that it may highlight several different Run objects at a time). I have tried this example http://blogs.microsoft.co.il/blogs/tamir/archive/2008/05/12/search-and

Binding to static class property

吃可爱长大的小学妹 提交于 2019-12-17 05:01:17
问题 I want to bind a textblock text to a property of a static class. Whenever the property value of the static class changes, it should reflect to the textblock which is on the other window or custom control. 回答1: You can bind to ANY property on a static class using the x:Static markup extension but if thy do not implement any change tracking, it might cause errors on the refresh! <TextBlock Text="{Binding Source={x:Static sys:Environment.MachineName}}" /> 回答2: This has worked for me: Text="

How to bind multiple values to a single WPF TextBlock?

冷暖自知 提交于 2019-12-17 02:04:39
问题 I'm currently using the TextBlock below to bind the value of a property named Name : <TextBlock Text="{Binding Name}" /> Now, I want to bind another property named ID to the same TextBlock . Is it possible to bind two or more values to the same TextBlock ? Can it be done with simple concatenation, like Name + ID and, if not, how else could this be approached? 回答1: You can use a MultiBinding combined with the StringFormat property. Usage would resemble the following: <TextBlock> <TextBlock

StringFormat with value zero

落爺英雄遲暮 提交于 2019-12-13 21:26:35
问题 I'm developing a wpf application with componentart I have a textblock like this <TextBlock FontSize="28" Text="{Binding DataPoint.Y, StringFormat=\{0:#\\%\}}" Foreground="Black"> As you can see, my StringFormat puts a '%' sign after the number, but if my data is 0.0 (I fill the component in code behind, my variable is a double) I get "%", but I want to get "0%", how can I do this? 回答1: you can use different StringFormat . Instead of 0:# put 0:0 : <TextBlock FontSize="28" Text="{Binding Path

Preserving indenting when wrapping in a wpf textblock control

大憨熊 提交于 2019-12-13 18:41:41
问题 I have a WPF textblock set up with the property TextWrapping="Wrap". When I pass in a long string with a tab character (vbTab in my case) at the start, I would like the wrapping to honour this and keep the wrapped parts of the string indented. For example, instead of: [vbTab]thisisreallylong andwrapped I want [vbTab]thisisreallylong [vbTab]andwrapped and ideally for multiple tabs, etc. too. [edit - additional details] Because the textblock will be of variable size and contain multiple lines

TextBlock Won't Update

百般思念 提交于 2019-12-13 16:19:25
问题 I have a TextBlock ( caloriesAvailableTextBlock ) which I am trying to update. The Button ( eatCaloriesButton ) is supposed to reduce the number which the TextBlock is bound to by 100. However, the TextBlock will not update. It just remains at 2000. Any ideas what I am missing? My xaml in HubPage.xaml: <StackPanel> <TextBlock TextWrapping="Wrap" Text="Calories Available:" FontSize="24"/> <TextBlock x:Name="caloriesAvailableTextBlock" Loaded="caloriesAvailableTextBlock_Loaded" TextWrapping=

TextBlock TextWrapping not wrapping #2

牧云@^-^@ 提交于 2019-12-13 13:17:29
问题 OK... so this solution doesn't help XAML is here <ListBox ItemsSource="{Binding Path=ContentItems}" Background="White" > <ListBox.ItemTemplate> <DataTemplate> <Grid Margin="2" Height="Auto" Width="Auto"> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto" /> <ColumnDefinition Width="*" /> </Grid.ColumnDefinitions> <Grid Grid.Column="0"> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="Auto"/> </Grid.RowDefinitions> <StackPanel Grid.Row="0" Orientation=