• 11.02.2026, 22:23
  • 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.

Endless

Newbie

Math in XAML objects

Sunday, February 2nd 2025, 6:15am

I'm trying to make a custom widget with the User Defined feature and I can't find any way to make a bar graph. I'm assuming I need to adjust the margins of the rectangle to change the size and shape of the "fill" of the bar graph, but I can't find a valid way to do that with XAML without trying to import external libraries.

e.g.

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<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"
   xmlns:sys="clr-namespace:System;assembly=mscorlib"
   mc:Ignorable="d"
   d:DesignHeight="200"
   d:DesignWidth="300">
   <Grid>
      <Grid.RowDefinitions>
         <RowDefinition />
      </Grid.RowDefinitions>
      <Rectangle
         Grid.Row="0"
         Opacity="1.0"
         Margin="7,7,7,7"
         RadiusX="0"
         RadiusY="0">
         <Rectangle.Style>
            <Style
               TargetType="{x:Type Rectangle}">
               <Style.Triggers>
                  <DataTrigger
                     Value="True"
                     Binding="{Binding ElementName=this, Path=DataContext.Value, ConverterParameter=0, Converter={StaticResource CompareSmallerConverter}}">
                     <Setter
                        Property="Margin"
                        Value="this.Height / 100 * DataContext.value, 0, 0, 0" />
                  </DataTrigger>
                  <DataTrigger
                     Value="False"
                     Binding="{Binding ElementName=this, Path=DataContext.Value, ConverterParameter=0, Converter={StaticResource CompareSmallerConverter}}">
                     <Setter
                        Property="Fill"
                        Value="Green" />
                  </DataTrigger>
               </Style.Triggers>
            </Style>
         </Rectangle.Style>
      </Rectangle>
   </Grid></UserControl>


Any pointers? Is there a way to see the XAML behind existing components so I could just reverse engineer how existing graphs are made?