• 21.07.2025, 08:27
  • S’inscrire
  • Connexion
  • Vous n’êtes pas connecté.

 

Bonjour, visiteur, bienvenue sur les forums Aqua Computer Forum. Si c’est votre première visite, nous vous invitons à consulter l’Aide. Elle vous expliquera le fonctionnement de cette page. Pour avoir accès à toutes les fonctionnalités, vous devez vous inscrire. Pour cela, veuillez utiliser le formulaire d’enregistrement, ou bien lisez plus d’informations sur la procédure d’enregistrement. Si vous êtes déjà enregistré, veuillez vous connecter.

Endless

Newbie

Math in XAML objects

dimanche 2 février 2025, 06:15

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.

Code source

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?

Discussions similaires