<Window.Resources> <DataTemplate x:Key="styleJour"> <StackPanel Background="Gray" Height="Auto" HorizontalAlignment="Left" Name="grdJournee" VerticalAlignment="Top" Width="Auto" Orientation="Horizontal" Margin="0,1" > <TextBox Width="9" Height="16" HorizontalAlignment="Left" VerticalAlignment="Center" FontSize="7" x:Name="jourDeLaSemaine" Text="{Binding Mode=OneWay, Path=JourString}" BorderThickness="0" Background="{Binding Couleur}" Focusable="False" /> <TextBox Width="12" Height="16" HorizontalAlignment="Left" VerticalAlignment="Center" FontSize="7" x:Name="jourDuMoi" Text="{Binding JourDansMoi, Mode=OneWay}" BorderThickness="0" Background="{Binding Couleur}" Focusable="False" /> <TextBox Width="53" Height="16" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="7" x:Name="descriptionJour" Text="{Binding Description}" HorizontalContentAlignment="Center" BorderThickness="0" Background="{Binding Couleur}" Focusable="False" /> </StackPanel> </DataTemplate> <DataTemplate x:Key="styleSemaine"> <Grid Background="Pink" Height="Auto" HorizontalAlignment="Center" Name="grdSemaine" VerticalAlignment="Center" Width="Auto" Margin="1,1,1,1"> <TextBlock Name="txtNumSemaine" VerticalAlignment="Center" Text="{Binding Path=NumeroAffiche}" HorizontalAlignment="Left" FontSize="8" Background="Red"> <TextBlock.RenderTransform> <TransformGroup> <RotateTransform CenterX="{Binding Path=CenterX}" CenterY="{Binding Path=CenterY}" Angle="90"/> </TransformGroup> </TextBlock.RenderTransform> </TextBlock> <ListBox Height="Auto" ScrollViewer.HorizontalScrollBarVisibility="Hidden" ScrollViewer.VerticalScrollBarVisibility="Hidden" ItemTemplate="{StaticResource styleJour}" ItemsSource="{Binding Path=.Journees}" HorizontalAlignment="Left" Margin="17,0,0,0" x:Name="lstJours" VerticalAlignment="Top" Width="Auto"></ListBox> </Grid> </DataTemplate> <DataTemplate x:Key="styleMoi"> <Grid Background="Azure" Height="Auto" Width="Auto"> <TextBox Height="17" Width="100" Text="{Binding Nom}" VerticalAlignment="Top" Name="txMoi" BorderThickness="0" HorizontalContentAlignment="Center" FontSize="13" /> <ListBox Height="Auto" ScrollViewer.HorizontalScrollBarVisibility="Hidden" ScrollViewer.VerticalScrollBarVisibility="Hidden" ItemTemplate="{StaticResource styleSemaine}" ItemsSource="{Binding Path=.Semaines}" HorizontalAlignment="Left" Margin="0,17,0,0" Name="lstMoi" VerticalAlignment="Top" Width="Auto" BorderThickness="0"></ListBox> </Grid> </DataTemplate> </Window.Resources> <Grid> <ListBox Height="615" Width="1263" ScrollViewer.HorizontalScrollBarVisibility="Hidden" ScrollViewer.VerticalScrollBarVisibility="Hidden" ItemTemplate="{StaticResource styleMoi}" ItemsSource="{Binding}" HorizontalAlignment="Left" Name="lstCalendrier" VerticalAlignment="Top" VerticalContentAlignment="Top" Margin="0,40,0,0" Background="LightYellow"> <ListBox.ItemsPanel> <ItemsPanelTemplate> <StackPanel Orientation="Horizontal" Margin="0"></StackPanel> </ItemsPanelTemplate> </ListBox.ItemsPanel> <ListBox.RenderTransform> <!--Zoom Bindé sur le slider--> <TransformGroup> <ScaleTransform> <ScaleTransform.ScaleX> <Binding ElementName="sldZoom" Path="Value" Mode="OneWay"/> </ScaleTransform.ScaleX> <ScaleTransform.ScaleY> <Binding ElementName="sldZoom" Path="Value" Mode="OneWay"/> </ScaleTransform.ScaleY> </ScaleTransform> </TransformGroup> </ListBox.RenderTransform> </ListBox> <Slider Height="25" HorizontalAlignment="Left" Margin="12,0,0,0" Name="sldZoom" VerticalAlignment="Top" Width="235" Maximum="1.5" Value="1" Minimum="0.5" LargeChange="0.05"/> </Grid> </Window>
Donc en gros ce que tu me dis, WPF est prévu pour les projets statiques.non pas du tout dans mon exemple le xalm ne sait pas d'avance combien je lui envoie de mois, combien de semaines par moi, combien de jours par semaines.
Je l'ai mis comme ci dessus mon Template, mais il est dans une méthode statique (donc utilisable dans l'état par tout le logiciel).un template est une ressource. Tu peux créer un dictionnaire de ressource que tu appelles d'ou tu veux. (Je ne l'ai pas encore fait)
Mon problème principal vient du fait que j'ai des photos utilisateurs qui peuvent être modifiées. La photo s'affiche, on peut rechercher une nouvelle photo, mais lorsque je veux l'enregistrer, celle-ci étant accrochée au logiciel, j'ai un refus d'écriture. Donc je dois tout d'abord charger ce fichier en ram et l'afficher depuis cet emplacement. Et là je ne vois pas comment, je peux utiliser les template qui me donne la forme de mes controls et charger une image qui est en RAM.je ne comprends pas ce que tu veux dire
Venant du Winform, je suis frustré par le fait que l'on puisse pas tout faire en WPF par le code et se servir du XAML pour ce qui reste statique (faudra s'y habituer et trouver des parades).comme je l'ai dit plus je ne maitrise pas encore mais sur la base de lecture de tutos, du livre cité plus haut et de mes collègues, je peux affirmer qu'au contraire tu peux faire beaucoup plus de choses dynamiquement.
template += "<ImageBrush ImageSource=\"" + img + "\" />";
<ControlTemplate x:Key="T_Boutons" TargetType="Button"> <Border CornerRadius="20" BorderThickness="1" BorderBrush="Black"> <ContentPresenter/> <Border.Background> <ImageBrush Stretch="Uniform" TileMode="None" ImageSource="{Binding Photo}" /> </Border.Background> </Border> </ControlTemplate>
<Button Template="{StaticResource T_Boutons}" Height="100" HorizontalAlignment="Left" Margin="10,10,0,0" Name="Retour" VerticalAlignment="Top" Width="100" Click="Retour_Click" />