1 pièce(s) jointe(s)
WPF : Même code, pas même résultat
Bonjour,
J'ai 2 codes qui me semblent identiques et pourtant je n'ai pas le même rendu...
J'ai fait un préprojet pour valider un rendu
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
| <Window x:Class="WpfApp6.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApp6"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<DataTemplate x:Key="ObjectDataTemplate">
<GroupBox Header="{Binding Name}">
<ItemsControl ItemsSource="{Binding Tests}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition SharedSizeGroup="Name"/>
<ColumnDefinition SharedSizeGroup="Value"/>
<ColumnDefinition SharedSizeGroup="Symbol"/>
</Grid.ColumnDefinitions>
<Label Content="{Binding Name}"/>
<TextBox Grid.Column="1" Text="{Binding Value}" HorizontalContentAlignment="Center"/>
<Label Grid.Column="2" Content="{Binding Symbol}"/>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</GroupBox>
</DataTemplate>
<ItemsPanelTemplate x:Key="GroupPanelTemplate">
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</Window.Resources>
<ItemsControl Name="Measure"
Grid.IsSharedSizeScope="true"
ItemsSource="{Binding}"
ItemTemplate="{StaticResource ObjectDataTemplate}"
ItemsPanel="{StaticResource GroupPanelTemplate}"
VerticalAlignment="Center"/>
</Window> |
Avec le code suivant:
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 44 45 46 47 48 49 50 51
| using System.Windows;
namespace WpfApp6
{
/// <summary>
/// Logique d'interaction pour MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
DataContext = new Group[]
{
new Group
{
Name = "TestGroup111",
Tests = new Test[]
{
new Test { Name = "Test1", Value = 5, Symbol = "%" },
new Test { Name = "Test1Test", Value = 105, Symbol = "mm/s" },
new Test { Name = "Test1ff", Value = 15, Symbol = "i" }
}
},
new Group
{
Name = "TestGroup222",
Tests = new Test[]
{
new Test { Name = "Test2", Value = 25, Symbol = "%" },
new Test { Name = "Test2Test", Value = 8, Symbol = "mm/s" },
new Test { Name = "Test2ff", Value = 45, Symbol = "i" }
}
}
};
}
}
public class Group
{
public string Name { get; set; }
public Test[] Tests { get; set; }
}
public class Test
{
public string Name { get; set; }
public int Value { get; set; }
public string Symbol { get; set; }
}
} |
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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
| <UserControl x:Class="DigitalFactory.UserControls.ActiveParametersPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:DigitalFactory.ViewModels"
mc:Ignorable="d">
<UserControl.DataContext>
<local:ActiveParametersPageViewModel/>
</UserControl.DataContext>
<!--<UserControl.Resources>
<ItemsPanelTemplate x:Key="ItemsPanelTemplateHorizontal">
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
<DataTemplate x:Key="ParameterInLineTemplate" DataType="{x:Type local:Parameter}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition SharedSizeGroup="Name"/>
<ColumnDefinition SharedSizeGroup="Value"/>
<ColumnDefinition SharedSizeGroup="Symbol"/>
</Grid.ColumnDefinitions>
<Label Content="{Binding Name, Converter={StaticResource ParameterConverter}}"/>
<TextBox Text="{Binding ParameterInputs.Value}" Grid.Column="1" MinWidth="50" HorizontalContentAlignment="Center"/>
<Label Content="{Binding ParameterUnit.Symbol}" Grid.Column="2"/>
</Grid>
</DataTemplate>
<DataTemplate x:Key="ParameterGroupScreenTemplate" DataType="{x:Type local:ParameterGroupScreen}">
<GroupBox Header="{Binding Name}">
<!--<ItemsControl ItemsSource="{Binding Parameters}" ItemTemplate="{StaticResource ParameterInLineTemplate}"/>-->
<ItemsControl ItemsSource="{Binding Parameters}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition SharedSizeGroup="Name"/>
<ColumnDefinition SharedSizeGroup="Value"/>
<ColumnDefinition SharedSizeGroup="Symbol"/>
</Grid.ColumnDefinitions>
<Label Content="{Binding Name}"/>
<TextBox Grid.Column="1" Text="{Binding ParameterInputs.Value}" MinWidth="50" HorizontalContentAlignment="Center"/>
<Label Grid.Column="2" Content="{Binding ParameterUnit.Symbol}"/>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</GroupBox>
</DataTemplate>
</UserControl.Resources>
<ItemsControl Name="ParameterGroups"
ItemsSource="{Binding ParameterGroups}"
ItemTemplate="{StaticResource ParameterGroupScreenTemplate}"
ItemsPanel="{StaticResource ItemsPanelTemplateHorizontal}"
Grid.IsSharedSizeScope="True"
VerticalContentAlignment="Top"
VerticalAlignment="Center"/>-->
<UserControl.Resources>
<DataTemplate x:Key="ObjectDataTemplate">
<GroupBox Header="{Binding Name}">
<ItemsControl ItemsSource="{Binding Parameters}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition SharedSizeGroup="Name"/>
<ColumnDefinition SharedSizeGroup="Value"/>
<ColumnDefinition SharedSizeGroup="Symbole"/>
</Grid.ColumnDefinitions>
<Label Content="{Binding Name}"/>
<TextBox Grid.Column="1" Text="{Binding ParameterInputs.Value}" HorizontalContentAlignment="Center"/>
<Label Grid.Column="2" Content="{Binding ParameterUnit.Symbol}"/>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</GroupBox>
</DataTemplate>
<ItemsPanelTemplate x:Key="GroupPanelTemplate">
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</UserControl.Resources>
<ItemsControl Name="Measure"
Grid.IsSharedSizeScope="true"
ItemsSource="{Binding ParameterGroups}"
ItemTemplate="{StaticResource ObjectDataTemplate}"
ItemsPanel="{StaticResource GroupPanelTemplate}"
VerticalAlignment="Center"/>
</UserControl> |
Avec le code suivant :
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
| namespace DigitalFactory.ViewModels
{
using Objects.Entities;
using Objects.Entities.Context;
using Objects.Extensions;
using Objects.Log;
using Properties;
using System;
using System.Data.Entity;
using System.Linq;
public class ActiveParametersPageViewModel
{
public IOrderedEnumerable<ParameterGroupScreen> ParameterGroups
{
get
{
string IHMName = GetType().Name.IHMName();
using (MachineDBContext resource = new MachineDBContext())
return resource.ParameterGroupScreens
.Include(o => o.Parameters.Select(p => p.ParameterInputs))
.Include(o => o.Parameters.Select(p => p.ParameterUnit))
.Where(o => o.Parameters.Any(p => p.ParameterAddresses.Any(q => q.Machine.BusinessReference == Settings.Default.BusinessReference)) &&
o.PresentationPage.Name == IHMName &&
o.Parameters.Count > 0)
.ToList()
.OrderBy(o => o.OrderInPage);
}
}
}
} |
Avec la définition de mes objets :
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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
| namespace DigitalFactory.Objects.Entities
{
using Bases;
using System;
public class ParameterGroupScreen
{
public ParameterGroupScreen () => Parameters = new HashSet<Parameter>();
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid ID { get; set; }
[Required]
[Index(IsUnique = true)]
[StringLength(50)]
public string Name { get; set; }
public virtual ICollection<Parameter> Parameters { get; set; }
public int OrderInPage { get; set; }
public Guid PresentationPageID { get; set; }
public virtual PresentationPage PresentationPage { get; set; }
}
public class Parameter
{
public Parameter()
{
ParameterAddresses = new HashSet<ParameterAddress>();
ParameterFixedValues = new HashSet<ParameterFixedValue>();
ParameterInputs = new HashSet<ParameterInput>();
ParameterOutputs = new HashSet<ParameterOutput>();
}
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid ID { get; set; }
[Required]
[Index(IsUnique = true)]
[StringLength(50)]
public string Name { get; set; }
public bool IsAutomaton { get; set; } = true;
public int OrderInGroupScreen { get; set; }
public int OrderInOpcGroup { get; set; }
public Guid ParameterGroupScreenID { get; set; }
public virtual ParameterGroupScreen ParameterGroupScreen { get; set; }
public Guid ParameterUnitID { get; set; }
public virtual ParameterUnit ParameterUnit { get; set; }
public virtual ICollection<ParameterInput> ParameterInputs { get; set; }
}
public class ParameterInput
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid ID { get; set; }
public Guid ParameterID { get; set; }
public virtual Parameter Parameter { get; set; }
public double Value { get; set; }
}
public class ParameterUnit
{
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid ID { get; set; }
public Guid ParameterID { get; set; }
public virtual Parameter Parameter { get; set; }
[Index(IsUnique = true)]
[StringLength(15)]
public string Symbol { get; set; }
}
} |
Le premier code me donne le formulaire sur fond blanc, les groupes sont les uns à côté des autres et les paramètres sont les uns en dessous des autres, et le second le formulaire sur fond noir, les groupes et les paramètres sont les uns à côté des autres.
Pièce jointe 435948
Pourtant j'ai les mêmes codes (et en commentaire dans le XAML, l'ancien code que je voulait faire mais qui me donne le même résultat).
Auriez-vous une idée ?