• 04.05.2026, 11:34
  • Register
  • Login
  • You are not logged in.

 

Dear visitor, welcome to Aqua Computer Forum. If this is your first visit here, please read the Help. It explains how this page works. You must be registered before you can use all the page's features. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

SeeBastion

Junior Member

Sensorwerte Runden in yaml

Tuesday, October 31st 2023, 12:25pm

Wie kann ich die Sensorwerte in einem Benutzerdefinierten Objekt runden? Das Objekt ist mit einem Sensor aus dem Playground verknüft und zeigt 1 Nachkommastelle, ich möchte nun auf 0 nackommastellen "Runden". Hier mein bisheriger Code:
<UserControl
x:Name="this"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.66*"/>
<ColumnDefinition Width="0.33*"/>
</Grid.ColumnDefinitions>
<TextBlock
Margin="0,0,0,3"
Text="Power"
FontSize="14" HorizontalAlignment="Left" VerticalAlignment="Center" FontFamily="Comic Sans MS"/>
<TextBlock
Grid.Column="1" Margin="0,0,0,3" FontSize="14" FontFamily="Comic Sans MS"
HorizontalAlignment="Right" VerticalAlignment="Center">
<TextBlock.Text>
<MultiBinding Converter="{StaticResource UnitConverter}" ConverterParameter="1">
<Binding ElementName="this" Path="DataContext.Data"/>
<Binding ElementName="this" Path="DataContext.Data.v"/>
</MultiBinding>
</TextBlock.Text>
</TextBlock>
<Rectangle VerticalAlignment="Bottom" Height="0" Grid.ColumnSpan="2" Fill="White" Opacity="0.15"/>
</Grid>
</UserControl>

Peter von Frosta

Full Member

Tuesday, October 31st 2023, 1:21pm

Versuche es mal so:

Quoted

<UserControl
x:Name="this"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.66*"/>
<ColumnDefinition Width="0.33*"/>
</Grid.ColumnDefinitions>
<TextBlock
Margin="0,0,0,3"
Text="Power"
FontSize="14" HorizontalAlignment="Left" VerticalAlignment="Center" FontFamily="Comic Sans MS"/>
<TextBlock
Text="{Binding ElementName=this, Path=DataContext.Value, StringFormat={}{0:F0}, FallbackValue=nix da}"
Grid.Column="1"
FontSize="14"
FontFamily="Comic Sans MS"
FontWeight="Normal"
Margin="0,0,0,3"
HorizontalAlignment="Center"
VerticalAlignment="Center"/>
<Rectangle VerticalAlignment="Bottom" Height="0" Grid.ColumnSpan="2" Fill="White" Opacity="0.15"/>
</Grid>
</UserControl>

This post has been edited 2 times, last edit by "Peter von Frosta" (Oct 31st 2023, 1:29pm)

SeeBastion

Junior Member

Tuesday, October 31st 2023, 3:28pm

Hm, das funktioniert an sich, allerdings fehlt dann die Einheit hinten dran.

Peter von Frosta

Full Member

Tuesday, October 31st 2023, 3:44pm

Dann musst Du die noch mit einem weiteren TextBlock hinten dran hängen.
Runden kann man nur Zahlen...

SeeBastion

Junior Member

Tuesday, October 31st 2023, 3:54pm

klappt nicht so recht. kann man bei "StringFormat" die Einheit mit reinpacken?
Von Python o.ä. kenn ich das so, da kann man meist das Zahlenformat definieren und Pre- oder Suffixe mit dran packen.

SeeBastion

Junior Member

Tuesday, October 31st 2023, 4:00pm

Ok, jetzt hat es durch probieren geklappt. Habe jetzt das hier benutzt:

StringFormat='{}{0:F0} W'
Danke für die Hilfe :thumbsup:

Peter von Frosta

Full Member

Tuesday, October 31st 2023, 4:02pm

Kannst Du sogar in die gleiche Zelle schreiben wie den Wert, musst nur beim Wert etwas "Margin rechts" hinzufügen

Quoted

<UserControl
x:Name="this"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.66*"/>
<ColumnDefinition Width="0.33*"/>

</Grid.ColumnDefinitions>
<TextBlock
Margin="0,0,0,3"
Text="Power"
FontSize="14" HorizontalAlignment="Left" VerticalAlignment="Center" FontFamily="Comic Sans MS"/>

<TextBlock
Text="{Binding ElementName=this, Path=DataContext.Value, StringFormat={}{0:F0}, FallbackValue=nix da}"
Grid.Column="1"
FontSize="14"
FontFamily="Comic Sans MS"
FontWeight="Normal"
Margin="0,0,20,3"
HorizontalAlignment="right"
VerticalAlignment="Center"/>


<TextBlock
Grid.Column="1"
Text="W"
Margin="0,0,0,3"
FontSize="14" HorizontalAlignment="Right" VerticalAlignment="Center" FontFamily="Comic Sans MS"/>


<Rectangle VerticalAlignment="Bottom" Height="0" Grid.ColumnSpan="2" Fill="White" Opacity="0.15"/>
</Grid>
</UserControl>

Peter von Frosta

Full Member

Tuesday, October 31st 2023, 4:03pm

Ok, jetzt hat es durch probieren geklappt. Habe jetzt das hier benutzt:

StringFormat='{}{0:F0} W'
Danke für die Hilfe :thumbsup:
Das geht auch (ich war zu langsam :rolleyes: )