I am very new to wpf and xaml and I appreciate your help!... I need to round (to two decimal places) the Hookload STRING representation of a floating point decimal value (example "128.34956483727845956" will display "128.35" on the label). I believe the problem is that I am bringing in a string... Nothing I've tried works.
My current code is as follows:
<TextBlock x:Name="Hookload" Text="{Binding Path=Hookload.Value, StringFormat={}{0:N0}%}" Background="White" FontSize="12" FontWeight="Bold" TextBlock.TextAlignment="Center" Margin="17,60,0,0" HorizontalAlignment="Left" Height="42" Width="138" VerticalAlignment="Top" Padding="0">
</TextBlock>
I've tried everything I can find to truncate or round to any decimal place using a label and TextBlock:
StringFormat={}{0:N0}%}
ContentStringFormat="{}{0:N0}%"
StringFormat=N2
StringFormat=N{0}
TextTrimming="CharacterEllipsis"
PLEASE HELP!!!! Thank you!
More attempts from suggestions:
I'm trying to implement the IValueconverter now from this example: Can you limit the length of Text visible in a WPF TextBlock? and adding a custom namespace to xaml
BUT I'm having problem with this:
Error 6 The name "MyTruncateConverter" does not exist in the namespace "clr-namespace:MyTruncateConverter". C:\Projects\FlexView2.0\FlexView\Src\Presentation\DashboardModule\Views\DetailView.xaml 19 9 DashboardModule Error 7 The type 'local:MyTruncateConverter' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built. C:\Projects\FlexView2.0\FlexView\Src\Presentation\DashboardModule\Views\DetailView.xaml 19 10 DashboardModule
My code for this attempt is here: The second to last line is where the error occurs.
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:AttachedCommand="clr-namespace:WPF.RealTime.Infrastructure.AttachedCommand;assembly=WPF.RealTime.Infrastructure"
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:AttachedProperty="clr-namespace:WPF.RealTime.Infrastructure.AttachedProperty;assembly=WPF.RealTime.Infrastructure"
xmlns:System="clr-namespace:System;assembly=mscorlib"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" x:Class="DashboardModule.Views.DetailView"
xmlns:local="clr-namespace:MyTruncateConverter"
Title="Rig Detail"
SizeToContent="WidthAndHeight"
WindowStyle="ToolWindow"
AttachedProperty:WindowProperties.Left="1"
AttachedProperty:WindowProperties.Top="1"
AttachedProperty:WindowProperties.Height="{x:Static AttachedProperty:WindowProperties.OneHalfHeight}"
AttachedProperty:WindowProperties.Width="{x:Static AttachedProperty:WindowProperties.HalfWidth}">
<Window.Resources>
<System:String x:Key="MyData">Lorem ipsum dolor sit amet, consectetur adipiscing elit.blah blah blah d et auctor nibh. Proin ac ultricies tellus.</System:String>
<local:MyTruncateConverter x:Key="MyConverter" />
</Window.Resources>
I am clearly lacking knowledge in how to add the class correctly. But I don't know how to fix this!
Point to namespace not class...
xmlns:local="clr-namespace:DashboardModule.Views"