Bonjour, j'ai cherché, j'ai cherché et je cherche encore...
J'ai dans mon projet plusieurs dictionnaires de ressources réservés chacun à des composants spécifiques. En particulier j'en ai un pour les styles appliqués aux ToggleButton, et un autre pour ceux des ListViewItem. Le deuxième appelant le premier.
celui des ListViewItem (il contient un toogle appelant le style situé dans le dictionnaire des ToggleButton) :
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
| <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:QTEST">
<SolidColorBrush x:Key="Item.MouseOver.Background" Color="#1F26A0DA"/>
<SolidColorBrush x:Key="Item.MouseOver.Border" Color="#a826A0Da"/>
<SolidColorBrush x:Key="Item.SelectedInactive.Background" Color="#3DDADADA"/>
<SolidColorBrush x:Key="Item.SelectedInactive.Border" Color="#FFDADADA"/>
<SolidColorBrush x:Key="Item.SelectedActive.Background" Color="#3D26A0DA"/>
<SolidColorBrush x:Key="Item.SelectedActive.Border" Color="#FF26A0DA"/>
<Style x:Key="FocusVisualStyle_1" TargetType="{x:Type ListViewItem}">
<Setter Property="BorderBrush" Value="Red"/>
</Style>
<Style x:Key="ListviewItemStyle_1" TargetType="ListViewItem">
<Setter Property="SnapsToDevicePixels" Value="True"/>
<Setter Property="Padding" Value="4,1"/>
<Setter Property="HorizontalContentAlignment" Value="{Binding HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
<Setter Property="VerticalContentAlignment" Value="{Binding VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisualStyle_1}"/>
<Setter Property="Visibility" Value="{Binding Path=visibilite}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListViewItem}">
<Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="30"/>
<ColumnDefinition Width="10"/>
<ColumnDefinition Width="{Binding Path=profondeur, Converter={StaticResource profondeurmargetreeviewitem}}"/>
<ColumnDefinition Width="20" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="18"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Grid.Column="0" Grid.Row="0" Text="{Binding Path=rang}"/>
<TextBlock Grid.Column="1" Grid.Row="0" Text="{Binding Path=profondeur}"/>
<ToggleButton Grid.Column="3" Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Center" SnapsToDevicePixels="True" x:Name="Expander" Style="{StaticResource TreeviewTogglePlusMoins}" IsChecked="{Binding Path=IsExpanded, RelativeSource={RelativeSource TemplatedParent}}" ClickMode="Press" />
<ContentPresenter Grid.Column="4" Grid.Row="0" Grid.RowSpan="2" Content="{Binding Path=lib_court}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
</ContentPresenter>
</Grid>
</Border>
<ControlTemplate.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="True"/>
</MultiTrigger.Conditions>
<Setter Property="Background" TargetName="Bd" Value="{StaticResource Item.MouseOver.Background}"/>
<Setter Property="BorderBrush" TargetName="Bd" Value="{StaticResource Item.MouseOver.Border}"/>
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="Selector.IsSelectionActive" Value="False"/>
<Condition Property="IsSelected" Value="True"/>
</MultiTrigger.Conditions>
<Setter Property="Background" TargetName="Bd" Value="{StaticResource Item.SelectedInactive.Background}"/>
<Setter Property="BorderBrush" TargetName="Bd" Value="{StaticResource Item.SelectedInactive.Border}"/>
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="Selector.IsSelectionActive" Value="True"/>
<Condition Property="IsSelected" Value="True"/>
</MultiTrigger.Conditions>
<Setter Property="Background" TargetName="Bd" Value="{StaticResource Item.SelectedActive.Background}"/>
<Setter Property="BorderBrush" TargetName="Bd" Value="{StaticResource Item.SelectedActive.Border}"/>
</MultiTrigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="TextElement.Foreground" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary> |
celui des ToggleButton :
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
| <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:QTEST"
xmlns:s="clr-namespace:System;assembly=mscorlib">
<Style x:Key="TreeviewTogglePlusMoins" TargetType="{x:Type ToggleButton}">
<Setter Property="Focusable" Value="False"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<Grid Width="12" Height="12" SnapsToDevicePixels="True">
<!-- Rectangle 9x9 pixels -->
<Rectangle Width="12" Height="12" Fill="LightGray" Stroke="Gray" SnapsToDevicePixels="True" />
<!--<Ellipse Width="15" Height="15" Stroke="#919191" SnapsToDevicePixels="true">
<Ellipse.Fill>
<LinearGradientBrush EndPoint="0.5,2" StartPoint="0.5,0">
<GradientStop Color="White" Offset="0"/>
<GradientStop Color="Silver" Offset="0.5"/>
<GradientStop Color="LightGray" Offset="1"/>
</LinearGradientBrush>
</Ellipse.Fill>
</Ellipse>-->
<!-- Vertical line inside rectangle -->
<Rectangle x:Name="ExpandPath" Width="1" Height="6" Stroke="Black" SnapsToDevicePixels="true" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<!-- Horizontal line inside rectangle -->
<Rectangle Width="6" Height="1" Stroke="Black" SnapsToDevicePixels="true" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter Property="Visibility" TargetName="ExpandPath" Value="Collapsed"/>
</Trigger>
<Trigger Property="IsChecked" Value="false">
<Setter Property="Visibility" TargetName="ExpandPath" Value="Visible"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<EventSetter Event="Click" Handler= "TreeviewExpander_Click"/>
</Style>
</ResourceDictionary> |
Mon problème est que je ne sais pas ou définir le gestionnaire d'évènement "TreeviewExpander_Click" appelé dans l'evensetter du togglebutton.
j'ai essayé au niveau de la classe de la fenêtre principale (MainWindow.xaml.vb) et au niveau de l'application (Application.xaml.vb) et dans un module séparé mais il renvoie toujours l'erreur
{"'Échec de la création d'un 'Handler' à partir du texte 'TreeviewExpander_Click'.' numéro de ligne '139' et position de ligne '36'."}
et
{"Impossible d'établir une liaison avec la méthode cible, car sa signature ou sa transparence de sécurité n'est pas compatible avec celle du type délégué."}
Voici le bloc de déclaration de l'évènement
1 2 3 4 5
|
Public Shared ReadOnly TreeviewExpander_ClickEvent As RoutedEvent = EventManager.RegisterRoutedEvent("TreeviewExpander_Click", RoutingStrategy.Direct, GetType(RoutedEvent), GetType(MainWindow))
Public Shared Sub TreeviewExpander_Click(sender As Object, e As RoutedEventArgs)
MsgBox("hello")
End Sub |
Je précise que l'ensemble des dictionnaires est bien fusionné au niveau de Application.xaml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
<Application x:Class="Application"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:QTEST"
xmlns:tools="clr-namespace:QTEST.Outils"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Dictionnaire\QtestToogle.xaml"/>
<ResourceDictionary Source="Dictionnaire\QtestTextbox.xaml"/>
<ResourceDictionary Source="Dictionnaire\QtestLabel.xaml"/>
<ResourceDictionary Source="Dictionnaire\QtestColorBrush.xaml"/>
<ResourceDictionary Source="Dictionnaire\QtestTemplateSelector.xaml"/>
<ResourceDictionary Source="Dictionnaire\QtestConverter.xaml"/>
<ResourceDictionary Source="Dictionnaire\QtestListViewItem.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application> |
Qu'est ce qui ne va pas avec WPF ?
Partager