none
datagrid dans une combobox RRS feed

  • Question

  • Bonjour, 

    J'ai une datagrid qui se trouve dans un template d'une combobox (dans le popup)

    <Popup x:Name="PART_Popup" AllowsTransparency="True" Grid.ColumnSpan="2" IsOpen="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}" Margin="1" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Placement="Bottom">
    	<Microsoft_Windows_Themes:SystemDropShadowChrome x:Name="Shdw" Color="Transparent" MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{Binding ActualWidth, ElementName=MainGrid}" Height="247" Width="337">
    		<Border x:Name="DropDownBorder" BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" BorderThickness="1" Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" Margin="0" HorizontalAlignment="Stretch" Width="Auto" Height="Auto" VerticalAlignment="Stretch">
    			<ScrollViewer x:Name="DropDownScrollViewer" Margin="-1" d:LayoutOverrides="VerticalAlignment">
    				<Grid RenderOptions.ClearTypeHint="Enabled" Background="White" Height="Auto" Width="Auto" HorizontalAlignment="Stretch">
    					<DataGrid x:Name="dtg_loc" Margin="0,29,0,0" Height="218" VerticalAlignment="Top" HorizontalAlignment="Left" Width="337" AutoGenerateColumns="False" 
    						ItemsSource="{TemplateBinding ItemsSource}" 
    						SelectedItem="{TemplateBinding SelectedItem}" 
    						SelectionChanged="dtg_loc_SelectionChanged" 
    						>
    						<DataGrid.Columns>
    							<DataGridTextColumn Binding="{Binding NIdLocalite}" Header="nIdLocalite" Visibility="Hidden" />
    							<DataGridTextColumn Binding="{Binding SCP}" Header="Code Postal" />
    							<DataGridTextColumn Binding="{Binding SLocalite}" Header="Localite" Width="200" />
    							<DataGridTextColumn Binding="{Binding Deal.SNom}" Header="Code Dealer" />                           
    						</DataGrid.Columns>
    					</DataGrid>
    				</Grid>
    			</ScrollViewer>
    		</Border>
    	</Microsoft_Windows_Themes:SystemDropShadowChrome>
    </Popup>



    Le selecteditem est lié au template parent (donc la combobox) et a la combobox, j'ai bien lié le selecteditem à cette propriété: 

    Localite selectedLoc;
    public Localite SelectedLoc
    {
    	get { return selectedLoc; }
    	set
    	{
    		selectedLoc = value;
    		SelectedEntCopy.Loc = new Localite(value);
    		//SelectedPays = SelectedEntCopy.Loc.UnPays;
    		RaisePropertyChanged("SelectedLoc");
    		//SelectedLocCopy = new Localite(value);
    
    	}
    }



    Quand je lance l'application, il me trouve bien la ligne, on voit bien qu'il la trouvée, mais il ne la sélectionne pas :aie:
    Quand je sélectionne une autre ligne dans une autre datagrid qui déclenche la propriété SelectedLoc, la ligne est sélectionnée comme il faut ...



    J4ai essayer la même datagrid en dehors d'un template, ca marche au poils.
    Auriez-vous une idée?

    • Modifié draco951 jeudi 13 juin 2013 15:07
    jeudi 13 juin 2013 15:04

Réponses

  • Désolé pour la lenteur, j'ai décidé de recrée moi même mon User Control :

    Le UserControl ( XAML) :

    <UserControl
    	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    	xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    	xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    	xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
        xmlns:local="clr-namespace:ControlDo"
        xmlns:ControlDo_Converter="clr-namespace:ControlDo.Converter"
    	xmlns:local_Views="clr-namespace:ControlDo.UC"
        xmlns:ViewModel="clr-namespace:ControlDo.UC.ViewModels"
        xmlns:views="clr-namespace:ControlDo.Views"
    	xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" 
        xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
        xmlns:System="clr-namespace:System;assembly=mscorlib" 
        mc:Ignorable="d"
    	x:Class="ControlDo.UCComboBoxActi"
    	x:Name="ComboBoxLocalite" 
    	Height="63" 
    	Width="237"
        >
    
        <!--<UserControl.DataContext>
            <ViewModel:VMUCCBLocalite x:Name="viewModel"/>
        </UserControl.DataContext>-->
    
        <UserControl.Resources>
            <local_Views:DatagridItemBehavior x:Key="DatagridItemBehavior"/>
            <ViewModel:VMUCCBActivite x:Key="vm" />
            
    		<ControlDo_Converter:IntToBool x:Key="IntToBool"/>
    		<Style x:Key="ComboBoxFocusVisual">
    			<Setter Property="Control.Template">
    				<Setter.Value>
    					<ControlTemplate>
    						<Rectangle Margin="4,4,21,4" SnapsToDevicePixels="true" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2"/>
    					</ControlTemplate>
    				</Setter.Value>
    			</Setter>
    		</Style>
    		<LinearGradientBrush x:Key="ButtonNormalBackground" EndPoint="0,1" StartPoint="0,0">
    			<GradientStop Color="#F3F3F3" Offset="0"/>
    			<GradientStop Color="#EBEBEB" Offset="0.5"/>
    			<GradientStop Color="#DDDDDD" Offset="0.5"/>
    			<GradientStop Color="#CDCDCD" Offset="1"/>
    		</LinearGradientBrush>
    		<SolidColorBrush x:Key="ButtonNormalBorder" Color="#FF707070"/>
    		<Geometry x:Key="DownArrowGeometry">M 0 0 L 3.5 4 L 7 0 Z</Geometry>
    		<Style x:Key="ComboBoxReadonlyToggleButton" TargetType="{x:Type ToggleButton}">
    			<Setter Property="OverridesDefaultStyle" Value="true"/>
    			<Setter Property="IsTabStop" Value="false"/>
    			<Setter Property="Focusable" Value="false"/>
    			<Setter Property="ClickMode" Value="Press"/>
    			<Setter Property="Template">
    				<Setter.Value>
    					<ControlTemplate TargetType="{x:Type ToggleButton}">
    						<Microsoft_Windows_Themes:ButtonChrome x:Name="Chrome" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderPressed="{TemplateBinding IsPressed}" SnapsToDevicePixels="true">
    							<Grid HorizontalAlignment="Right" Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}">
    								<Path x:Name="Arrow" Data="{StaticResource DownArrowGeometry}" Fill="Black" HorizontalAlignment="Center" Margin="3,1,0,0" VerticalAlignment="Center"/>
    							</Grid>
    						</Microsoft_Windows_Themes:ButtonChrome>
    						<ControlTemplate.Triggers>
    							<Trigger Property="IsChecked" Value="true">
    								<Setter Property="RenderPressed" TargetName="Chrome" Value="true"/>
    							</Trigger>
    							<Trigger Property="IsEnabled" Value="false">
    								<Setter Property="Fill" TargetName="Arrow" Value="#AFAFAF"/>
    							</Trigger>
    						</ControlTemplate.Triggers>
    					</ControlTemplate>
    				</Setter.Value>
    			</Setter>
    		</Style>
    		<LinearGradientBrush x:Key="TextBoxBorder" EndPoint="0,20" MappingMode="Absolute" StartPoint="0,0">
    			<GradientStop Color="#ABADB3" Offset="0.05"/>
    			<GradientStop Color="#E2E3EA" Offset="0.07"/>
    			<GradientStop Color="#E3E9EF" Offset="1"/>
    		</LinearGradientBrush>
    		<Style x:Key="ComboBoxEditableTextBox" TargetType="{x:Type TextBox}">
    			<Setter Property="OverridesDefaultStyle" Value="true"/>
    			<Setter Property="AllowDrop" Value="true"/>
    			<Setter Property="MinWidth" Value="0"/>
    			<Setter Property="MinHeight" Value="0"/>
    			<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
    			<Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/>
    			<Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
    			<Setter Property="Template">
    				<Setter.Value>
    					<ControlTemplate TargetType="{x:Type TextBox}">
    						<ScrollViewer x:Name="PART_ContentHost" Background="Transparent" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
    					</ControlTemplate>
    				</Setter.Value>
    			</Setter>
    		</Style>
    		<Style x:Key="ComboBoxToggleButton" TargetType="{x:Type ToggleButton}">
    			<Setter Property="OverridesDefaultStyle" Value="true"/>
    			<Setter Property="IsTabStop" Value="false"/>
    			<Setter Property="Focusable" Value="false"/>
    			<Setter Property="ClickMode" Value="Press"/>
    			<Setter Property="Template">
    				<Setter.Value>
    					<ControlTemplate TargetType="{x:Type ToggleButton}">
    						<Microsoft_Windows_Themes:ButtonChrome x:Name="Chrome" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderPressed="{TemplateBinding IsPressed}" RoundCorners="false" SnapsToDevicePixels="true" Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}">
    							<Path x:Name="Arrow" Data="{StaticResource DownArrowGeometry}" Fill="Black" HorizontalAlignment="Center" Margin="0,1,0,0" VerticalAlignment="Center"/>
    						</Microsoft_Windows_Themes:ButtonChrome>
    						<ControlTemplate.Triggers>
    							<Trigger Property="IsChecked" Value="true">
    								<Setter Property="RenderPressed" TargetName="Chrome" Value="true"/>
    							</Trigger>
    							<Trigger Property="IsEnabled" Value="false">
    								<Setter Property="Fill" TargetName="Arrow" Value="#AFAFAF"/>
    							</Trigger>
    						</ControlTemplate.Triggers>
    					</ControlTemplate>
    				</Setter.Value>
    			</Setter>
    		</Style>
    		<ControlTemplate x:Key="ComboBoxEditableTemplate" TargetType="{x:Type ComboBox}">
    			<Grid x:Name="Placement" SnapsToDevicePixels="true">
    				<Grid.ColumnDefinitions>
    					<ColumnDefinition Width="*"/>
    					<ColumnDefinition Width="Auto"/>
    				</Grid.ColumnDefinitions>
    				<Popup x:Name="PART_Popup" AllowsTransparency="true" Grid.ColumnSpan="2" IsOpen="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Placement="Bottom">
    					<Microsoft_Windows_Themes:SystemDropShadowChrome x:Name="Shdw" Color="Transparent" MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{Binding ActualWidth, ElementName=Placement}">
    						<Border x:Name="DropDownBorder" BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" BorderThickness="1" Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}">
    							<ScrollViewer x:Name="DropDownScrollViewer">
    								<Grid RenderOptions.ClearTypeHint="Enabled">
    									<Canvas HorizontalAlignment="Left" Height="0" VerticalAlignment="Top" Width="0">
    										<Rectangle x:Name="OpaqueRect" Fill="{Binding Background, ElementName=DropDownBorder}" Height="{Binding ActualHeight, ElementName=DropDownBorder}" Width="{Binding ActualWidth, ElementName=DropDownBorder}"/>
    									</Canvas>
    									<ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Contained" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
    								</Grid>
    							</ScrollViewer>
    						</Border>
    					</Microsoft_Windows_Themes:SystemDropShadowChrome>
    				</Popup>
    				<Microsoft_Windows_Themes:ListBoxChrome x:Name="Border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Grid.ColumnSpan="2" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderFocused="{TemplateBinding IsKeyboardFocusWithin}"/>
    				<TextBox x:Name="PART_EditableTextBox" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" IsReadOnly="{Binding IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}" Margin="{TemplateBinding Padding}" Style="{StaticResource ComboBoxEditableTextBox}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
    				<ToggleButton Grid.Column="1" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Style="{StaticResource ComboBoxToggleButton}"/>
    			</Grid>
    			<ControlTemplate.Triggers>
    				<Trigger Property="IsKeyboardFocusWithin" Value="true">
    					<Setter Property="Foreground" Value="Black"/>
    				</Trigger>
    				<Trigger Property="IsDropDownOpen" Value="true">
    					<Setter Property="RenderFocused" TargetName="Border" Value="true"/>
    				</Trigger>
    				<Trigger Property="HasItems" Value="false">
    					<Setter Property="Height" TargetName="DropDownBorder" Value="95"/>
    				</Trigger>
    				<Trigger Property="IsEnabled" Value="false">
    					<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
    					<Setter Property="Background" Value="#FFF4F4F4"/>
    				</Trigger>
    				<Trigger Property="IsGrouping" Value="true">
    					<Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
    				</Trigger>
    				<Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="true">
    					<Setter Property="Margin" TargetName="Shdw" Value="0,0,5,5"/>
    					<Setter Property="Color" TargetName="Shdw" Value="#71000000"/>
    				</Trigger>
    				<Trigger Property="ScrollViewer.CanContentScroll" SourceName="DropDownScrollViewer" Value="false">
    					<Setter Property="Canvas.Top" TargetName="OpaqueRect" Value="{Binding VerticalOffset, ElementName=DropDownScrollViewer}"/>
    					<Setter Property="Canvas.Left" TargetName="OpaqueRect" Value="{Binding HorizontalOffset, ElementName=DropDownScrollViewer}"/>
    				</Trigger>
    			</ControlTemplate.Triggers>
    		</ControlTemplate>
    		<Style x:Key="WatermarkedTextBox" >
    			<Setter Property="Control.Template" >
    				<Setter.Value>
    					<ControlTemplate TargetType="{x:Type TextBox}" >
    						<!-- Template derived from Default TextBoxBase. -->
    
    		
    		
    	<!-- Added the Label InternalWatermarkLabel together with the surrounding Grid. -->
    						<Grid>
    							<Microsoft_Windows_Themes:ListBoxChrome x:Name="Bd"
    								Background="{TemplateBinding Panel.Background}" 
    								BorderBrush="{TemplateBinding Border.BorderBrush}"
    								BorderThickness="{TemplateBinding Border.BorderThickness}"
    								RenderMouseOver="{TemplateBinding IsMouseOver}" 
    								RenderFocused="{TemplateBinding IsKeyboardFocusWithin}" 
    								SnapsToDevicePixels="True">
    								<ScrollViewer x:Name="PART_ContentHost"
    									SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                              />
    							</Microsoft_Windows_Themes:ListBoxChrome>
    							<Label x:Name="InternalWatermarkLabel" 
    								Content="{TemplateBinding Tag}" 
    								Visibility="Collapsed" Focusable="False"
    								Foreground="Silver"
    								Background="Transparent"
                                   />
    						</Grid>
    						<ControlTemplate.Triggers>
                            <!-- The multitrigger is responsible for showing and hiding the watermark. -->
    							<MultiTrigger>
    								<MultiTrigger.Conditions>
    									<Condition Property="IsFocused" Value="False" />
    									<Condition Property="Text" Value="" />
    								</MultiTrigger.Conditions>
    								<Setter Property="Visibility" TargetName="InternalWatermarkLabel"
    									Value="Visible" />
    							</MultiTrigger>
                            <!-- This trigger mimics the default behavior. -->
    							<Trigger Property="IsEnabled" Value="False" >
    								<Setter Property="Panel.Background" TargetName="Bd"
    									Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
    								<Setter Property="TextElement.Foreground"
    									Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
    							</Trigger>
    						</ControlTemplate.Triggers>
    					</ControlTemplate>
    				</Setter.Value>
    			</Setter>
    		</Style>
    
    
            <Storyboard x:Key="RowToAnimateDown">
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="bt_addActivite">
                    <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                    <EasingDoubleKeyFrame KeyTime="0:0:1" Value="29"/>
                </DoubleAnimationUsingKeyFrames>
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="bt_deleteActivite">
                    <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                    <EasingDoubleKeyFrame KeyTime="0:0:1" Value="29"/>
                </DoubleAnimationUsingKeyFrames>
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="bt_saveActivite">
                    <EasingDoubleKeyFrame KeyTime="0" Value="29"/>
                    <EasingDoubleKeyFrame KeyTime="0:0:1" Value="0"/>
                </DoubleAnimationUsingKeyFrames>
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="bt_cancelActivite">
                    <EasingDoubleKeyFrame KeyTime="0" Value="29"/>
                    <EasingDoubleKeyFrame KeyTime="0:0:1" Value="0"/>
                </DoubleAnimationUsingKeyFrames>
                <BooleanAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.IsEnabled)" Storyboard.TargetName="grid_Localite2_2">
                    <DiscreteBooleanKeyFrame KeyTime="0" Value="False"/>
                    <DiscreteBooleanKeyFrame KeyTime="0:0:1" Value="True"/>
                </BooleanAnimationUsingKeyFrames>
                <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(ToggleButton.IsChecked)" Storyboard.TargetName="ck_Activite">
                    <DiscreteObjectKeyFrame KeyTime="0">
                        <DiscreteObjectKeyFrame.Value>
                            <System:Boolean>True</System:Boolean>
                        </DiscreteObjectKeyFrame.Value>
                    </DiscreteObjectKeyFrame>
                    <DiscreteObjectKeyFrame KeyTime="0:0:0.1">
                        <DiscreteObjectKeyFrame.Value>
                            <System:Boolean>False</System:Boolean>
                        </DiscreteObjectKeyFrame.Value>
                    </DiscreteObjectKeyFrame>
                </ObjectAnimationUsingKeyFrames>
            </Storyboard>
            <Storyboard x:Key="RowToAnimationUp">
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="bt_addActivite">
                    <EasingDoubleKeyFrame KeyTime="0:0:1" Value="0"/>
                </DoubleAnimationUsingKeyFrames>
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="bt_deleteActivite">
                    <EasingDoubleKeyFrame KeyTime="0:0:1" Value="0"/>
                </DoubleAnimationUsingKeyFrames>
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="bt_saveActivite">
                    <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                    <EasingDoubleKeyFrame KeyTime="0:0:1" Value="29"/>
                </DoubleAnimationUsingKeyFrames>
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="bt_cancelActivite">
                    <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                    <EasingDoubleKeyFrame KeyTime="0:0:1" Value="29"/>
                </DoubleAnimationUsingKeyFrames>
                <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(ToggleButton.IsChecked)" Storyboard.TargetName="ck_Activite">
                    <DiscreteObjectKeyFrame KeyTime="0">
                        <DiscreteObjectKeyFrame.Value>
                            <System:Boolean>False</System:Boolean>
                        </DiscreteObjectKeyFrame.Value>
                    </DiscreteObjectKeyFrame>
                    <DiscreteObjectKeyFrame KeyTime="0:0:0.1">
                        <DiscreteObjectKeyFrame.Value>
                            <System:Boolean>True</System:Boolean>
                        </DiscreteObjectKeyFrame.Value>
                    </DiscreteObjectKeyFrame>
                </ObjectAnimationUsingKeyFrames>
            </Storyboard>
            <Storyboard x:Key="up">
            	<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="grid">
            		<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
            		<EasingDoubleKeyFrame KeyTime="0:0:1" Value="30"/>
            	</DoubleAnimationUsingKeyFrames>
    			<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="bt_addActivite">
                    <EasingDoubleKeyFrame KeyTime="0:0:1" Value="0"/>
                </DoubleAnimationUsingKeyFrames>
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="bt_deleteActivite">
                    <EasingDoubleKeyFrame KeyTime="0:0:1" Value="0"/>
                </DoubleAnimationUsingKeyFrames>
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="bt_saveActivite">
                    <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                    <EasingDoubleKeyFrame KeyTime="0:0:1" Value="29"/>
                </DoubleAnimationUsingKeyFrames>
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="bt_cancelActivite">
                    <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                    <EasingDoubleKeyFrame KeyTime="0:0:1" Value="29"/>
                </DoubleAnimationUsingKeyFrames>
    			<BooleanAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.IsEnabled)" Storyboard.TargetName="grid_Localite2_2">
                    <DiscreteBooleanKeyFrame KeyTime="0" Value="False"/>
                    <DiscreteBooleanKeyFrame KeyTime="0:0:1" Value="True"/>
                </BooleanAnimationUsingKeyFrames>
                <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(ToggleButton.IsChecked)" Storyboard.TargetName="ck_Activite">
                    <DiscreteObjectKeyFrame KeyTime="0">
                        <DiscreteObjectKeyFrame.Value>
                            <System:Boolean>False</System:Boolean>
                        </DiscreteObjectKeyFrame.Value>
                    </DiscreteObjectKeyFrame>
                    <DiscreteObjectKeyFrame KeyTime="0:0:0.1">
                        <DiscreteObjectKeyFrame.Value>
                            <System:Boolean>True</System:Boolean>
                        </DiscreteObjectKeyFrame.Value>
                    </DiscreteObjectKeyFrame>
                </ObjectAnimationUsingKeyFrames>
            </Storyboard>
            <Storyboard x:Key="down">
            	<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="grid">
            		<EasingDoubleKeyFrame KeyTime="0" Value="30"/>
            		<EasingDoubleKeyFrame KeyTime="0:0:1" Value="0"/>
            	</DoubleAnimationUsingKeyFrames>
    			<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="bt_addActivite">
                    <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                    <EasingDoubleKeyFrame KeyTime="0:0:1" Value="29"/>
                </DoubleAnimationUsingKeyFrames>
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="bt_deleteActivite">
                    <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                    <EasingDoubleKeyFrame KeyTime="0:0:1" Value="29"/>
                </DoubleAnimationUsingKeyFrames>
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="bt_saveActivite">
                    <EasingDoubleKeyFrame KeyTime="0" Value="29"/>
                    <EasingDoubleKeyFrame KeyTime="0:0:1" Value="0"/>
                </DoubleAnimationUsingKeyFrames>
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="bt_cancelActivite">
                    <EasingDoubleKeyFrame KeyTime="0" Value="29"/>
                    <EasingDoubleKeyFrame KeyTime="0:0:1" Value="0"/>
                </DoubleAnimationUsingKeyFrames>
                <BooleanAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.IsEnabled)" Storyboard.TargetName="grid_Localite2_2">
                    <DiscreteBooleanKeyFrame KeyTime="0" Value="False"/>
                    <DiscreteBooleanKeyFrame KeyTime="0:0:1" Value="True"/>
                </BooleanAnimationUsingKeyFrames>
                <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(ToggleButton.IsChecked)" Storyboard.TargetName="ck_Activite">
                    <DiscreteObjectKeyFrame KeyTime="0">
                        <DiscreteObjectKeyFrame.Value>
                            <System:Boolean>True</System:Boolean>
                        </DiscreteObjectKeyFrame.Value>
                    </DiscreteObjectKeyFrame>
                    <DiscreteObjectKeyFrame KeyTime="0:0:0.1">
                        <DiscreteObjectKeyFrame.Value>
                            <System:Boolean>False</System:Boolean>
                        </DiscreteObjectKeyFrame.Value>
                    </DiscreteObjectKeyFrame>
                </ObjectAnimationUsingKeyFrames>
            </Storyboard>
            <Storyboard x:Key="ToggleButtonCheck">
            	<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(ToggleButton.IsChecked)" Storyboard.TargetName="toggleButton">
            		<DiscreteObjectKeyFrame KeyTime="0">
            			<DiscreteObjectKeyFrame.Value>
            				<System:Boolean>False</System:Boolean>
            			</DiscreteObjectKeyFrame.Value>
            		</DiscreteObjectKeyFrame>
            		<DiscreteObjectKeyFrame KeyTime="0:0:0.1">
            			<DiscreteObjectKeyFrame.Value>
            				<System:Boolean>True</System:Boolean>
            			</DiscreteObjectKeyFrame.Value>
            		</DiscreteObjectKeyFrame>
            	</ObjectAnimationUsingKeyFrames>
            </Storyboard>
            <Storyboard x:Key="ToggleButtonUnCheck">
            	<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(ToggleButton.IsChecked)" Storyboard.TargetName="toggleButton">
            		<DiscreteObjectKeyFrame KeyTime="0">
            			<DiscreteObjectKeyFrame.Value>
            				<System:Boolean>True</System:Boolean>
            			</DiscreteObjectKeyFrame.Value>
            		</DiscreteObjectKeyFrame>
            		<DiscreteObjectKeyFrame KeyTime="0:0:0.1">
            			<DiscreteObjectKeyFrame.Value>
            				<System:Boolean>False</System:Boolean>
            			</DiscreteObjectKeyFrame.Value>
            		</DiscreteObjectKeyFrame>
            	</ObjectAnimationUsingKeyFrames>
            </Storyboard>
            <Storyboard x:Key="popupDeleteOpen">
            	<BooleanAnimationUsingKeyFrames Storyboard.TargetProperty="(Popup.IsOpen)" Storyboard.TargetName="popup_supprimer">
            		<DiscreteBooleanKeyFrame KeyTime="0" Value="False"/>
            		<DiscreteBooleanKeyFrame KeyTime="0:0:0.1" Value="True"/>
            	</BooleanAnimationUsingKeyFrames>
            </Storyboard>
            <Storyboard x:Key="popupDeleteClose">
            	<BooleanAnimationUsingKeyFrames Storyboard.TargetProperty="(Popup.IsOpen)" Storyboard.TargetName="popup_supprimer">
            		<DiscreteBooleanKeyFrame KeyTime="0" Value="True"/>
            		<DiscreteBooleanKeyFrame KeyTime="0:0:0.1" Value="False"/>
            	</BooleanAnimationUsingKeyFrames>
            </Storyboard>
            <Storyboard x:Key="DeleteShow">
            	<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Width)" Storyboard.TargetName="grid1">
            		<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
            		<EasingDoubleKeyFrame KeyTime="0:0:0.1" Value="300"/>
            	</DoubleAnimationUsingKeyFrames>
            	<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(ToggleButton.IsChecked)" Storyboard.TargetName="ck_supActi">
            		<DiscreteObjectKeyFrame KeyTime="0">
            			<DiscreteObjectKeyFrame.Value>
            				<System:Boolean>False</System:Boolean>
            			</DiscreteObjectKeyFrame.Value>
            		</DiscreteObjectKeyFrame>
            		<DiscreteObjectKeyFrame KeyTime="0:0:0.1">
            			<DiscreteObjectKeyFrame.Value>
            				<System:Boolean>True</System:Boolean>
            			</DiscreteObjectKeyFrame.Value>
            		</DiscreteObjectKeyFrame>
            	</ObjectAnimationUsingKeyFrames>
            </Storyboard>
            <Storyboard x:Key="DeleteHide">
            	<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Width)" Storyboard.TargetName="grid1">
            		<EasingDoubleKeyFrame KeyTime="0" Value="300"/>
            		<EasingDoubleKeyFrame KeyTime="0:0:0.1" Value="0"/>
            	</DoubleAnimationUsingKeyFrames>
            	<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(ToggleButton.IsChecked)" Storyboard.TargetName="ck_supActi">
            		<DiscreteObjectKeyFrame KeyTime="0">
            			<DiscreteObjectKeyFrame.Value>
            				<System:Boolean>True</System:Boolean>
            			</DiscreteObjectKeyFrame.Value>
            		</DiscreteObjectKeyFrame>
            		<DiscreteObjectKeyFrame KeyTime="0:0:0.1">
            			<DiscreteObjectKeyFrame.Value>
            				<System:Boolean>False</System:Boolean>
            			</DiscreteObjectKeyFrame.Value>
            		</DiscreteObjectKeyFrame>
            	</ObjectAnimationUsingKeyFrames>
            </Storyboard>
    
        </UserControl.Resources>
    	<UserControl.Triggers>
    		<EventTrigger RoutedEvent="ButtonBase.Click" SourceName="bt_addActivite">
    			<BeginStoryboard x:Name="RowToAnimationUp_BeginStoryboard" Storyboard="{StaticResource up}"/>
    		</EventTrigger>
    		<EventTrigger RoutedEvent="ButtonBase.Click" SourceName="bt_cancelActivite">
    			<BeginStoryboard x:Name="down_BeginStoryboard" Storyboard="{StaticResource down}"/>
    		</EventTrigger>
    		<EventTrigger RoutedEvent="ButtonBase.Click" SourceName="bt_saveActivite">
    			<BeginStoryboard x:Name="down_BeginStoryboard2" Storyboard="{StaticResource down}"/>
    		</EventTrigger>
    		<EventTrigger RoutedEvent="ButtonBase.Click" SourceName="bt_deleteActivite">
    			<BeginStoryboard x:Name="DeleteShow_BeginStoryboard" Storyboard="{StaticResource DeleteShow}"/>
    		</EventTrigger>
    		<EventTrigger RoutedEvent="ButtonBase.Click" SourceName="bt_supActiOui">
    			<BeginStoryboard x:Name="DeleteShow_BeginStoryboard1" Storyboard="{StaticResource DeleteHide}"/>
    		</EventTrigger>
    		<EventTrigger RoutedEvent="ButtonBase.Click" SourceName="bt_supActiNon">
    			<BeginStoryboard x:Name="DeleteHide_BeginStoryboard" Storyboard="{StaticResource DeleteHide}"/>
    		</EventTrigger>
        </UserControl.Triggers>
    
    	<Grid x:Name="LayoutRoot" 
              LostFocus="LayoutRoot_LostFocus">
    		<Grid.RowDefinitions>
    			<RowDefinition Height="0.968*"/>
    			<RowDefinition Height="0.032*"/>
    		</Grid.RowDefinitions>
                
            <ToggleButton 
                x:Name="toggleButton" 
                Grid.RowSpan="2" 
                Checked="toggleButton_Checked" 
                HorizontalContentAlignment="Left" 
                Click="toggleButton_Click" 
                >
            	<Grid Width="229" Margin="0">
            		<TextBlock 
    					x:Name="tb_cp" 
    					TextWrapping="Wrap" 
    					Text="{Binding SelectedActi.SActiviteFR, Source={StaticResource vm}, Mode=OneWay}" 
    					/>
                    <Popup 
    				    x:Name="pop" 
    				    PlacementTarget="{Binding ElementName=toggleButton, Mode=OneWay}" 
    				    StaysOpen="False"
    					Margin="0,0,177.334,0" 
    				    >
    
                        <!--StaysOpen="False"  IsOpen="{Binding IsChecked, ElementName=toggleButton}" -->
                        <kb:Resizer xmlns:kb="http://kent.boogaart/controls" Height="330" Width="430.909"  >
                            <DockPanel x:Name="DockPanel" Background="Black">
                            	<Grid x:Name="grid1" DockPanel.Dock="Right" Width="0">
                            		<Grid.Background>
                            			<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            				<GradientStop Color="Black" Offset="1"/>
                            				<GradientStop Color="White"/>
                            			</LinearGradientBrush>
                            		</Grid.Background>
                            		<Button 
    									x:Name="bt_supActiOui" 
    									Margin="20.591,0,0,114.5" 
    									HorizontalAlignment="Left" 
    									Width="124.5" 
    									Height="36" 
    									VerticalAlignment="Bottom" 
    									Command="{Binding RemoveActivite, Source={StaticResource vm}}" 
    									>
                            			<DockPanel>
    										<TextBlock Text="Oui" DockPanel.Dock="Right" VerticalAlignment="Center" Margin="10,0,0,0"/>
    										<Image Height="28" Source="/ControlDo;component/Images/Accept48.png" Stretch="Fill" Width="27"/>
    									</DockPanel>
                            			
                            		</Button>
                            		<Button x:Name="bt_supActiNon" Margin="149.091,0,26.409,114.5" Height="36" VerticalAlignment="Bottom">
                            			<DockPanel>
    										<TextBlock Text="Non" DockPanel.Dock="Right" VerticalAlignment="Center" Margin="10,0,0,0"/>
    										<Image Height="24" Source="/ControlDo;component/Images/Cancel48.png" Stretch="Fill" Width="26.333"/>
    									</DockPanel>
                            		</Button>
                            		<TextBlock Height="48" Margin="20.591,108,26.409,0" TextWrapping="Wrap" Text="Etes-vous sûr de vouloir supprimer cette localité ? " VerticalAlignment="Top" HorizontalAlignment="Center"/>
                            		<Image Height="48" Margin="116.591,30,135.409,0" Source="/ControlDo;component/Images/Alert48.png" Stretch="Fill" VerticalAlignment="Top"/>
                            		<CheckBox x:Name="ck_supActi" Content="CheckBox" Height="30" Margin="75.091,0,141.909,51" VerticalAlignment="Bottom" Visibility="Hidden"/>
                            	</Grid>
    							<Grid x:Name="grid2">
                            		<TextBox 
                            			Height="29" 
                            			TextWrapping="Wrap" 
                            			Text="{Binding FilterActi, Mode=TwoWay, Source={StaticResource vm}, UpdateSourceTrigger=PropertyChanged}" 
                            			VerticalAlignment="Top" 
                            			Style="{DynamicResource WatermarkedTextBox}" 
                            			Tag="Recherche"/>
                            		<StackPanel Orientation="Vertical" x:Name="grid_Localite2_2" Opacity="1" Width="34.569" Margin="0,29,0,0" HorizontalAlignment="Right" d:LayoutOverrides="Width">
                        							
                            			<StackPanel.Background>
                            				<LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
                            					<GradientStop Color="White" Offset="0" />
                            					<GradientStop Color="#FFBABABA" Offset="1" />
                            				</LinearGradientBrush>
                            			</StackPanel.Background>
                            			<Button 
                            				Command="{Binding AddActivite, Source={StaticResource vm}}" 
                            				Height="29.032" 
                            				x:Name="bt_addActivite" 
                            				VerticalAlignment="Bottom" >
                            				<Image 
                            					Source="/ControlDo;component/Images/Add48.png" 
                            					Height="16.532" 
                            					Width="14.032"/>
                            			</Button>
                            			<Button 
                            				
                            				Height="29.032" 
                            				x:Name="bt_deleteActivite" 
                            				VerticalAlignment="Bottom" 
                            				IsEnabled="{Binding SelectedIndex, Converter={StaticResource IntToBool}, ElementName=dataGrid3}" HorizontalAlignment="Left" Width="34.569" >
                            				
                            					<Image 
                            						Source="/ControlDo;component/Images/Delete48.png" 
                            						Width="14" />
                            				
                            			</Button>
                            			<Button 
                            				Command="{Binding SaveActivite, Source={StaticResource vm}}" 
                            				Height="0"  
                            				Margin="0,0,0,0" 
                            				x:Name="bt_saveActivite" 
                            				VerticalAlignment="Bottom"  
                            				HorizontalAlignment="Left" 
                            				Width="34.569" >
                            				<Image 
                            					Source="/ControlDo;component/Images/Save48.png" 
                            					Width="14"/>
                            			</Button>
                            			<Button 
                            				Command="{Binding CancelActivite, Source={StaticResource vm}}" 
                            				Height="0"  
                            				Margin="0,0,0,0" 
                            				x:Name="bt_cancelActivite" 
                            				VerticalAlignment="Bottom" 
                            				d:LayoutOverrides="HorizontalAlignment, HorizontalMargin">
                            				<Image 
                            					Source="/ControlDo;component/Images/Cancel48.png" 
                            					Width="14" />
                            			</Button>
                            			<CheckBox 
                            				x:Name="ck_Activite" 
                            				Content="" 
                            				HorizontalContentAlignment="Center" 
                            				VerticalContentAlignment="Center"  
                            				Visibility="Hidden" />
                            		</StackPanel>
                            		<DockPanel Margin="0,29,34.569,0" Background="#FFE5ACAC">
                            			<Grid x:Name="grid" DockPanel.Dock="Bottom" Height="0">
                            				<Grid.ColumnDefinitions>
                            					<ColumnDefinition Width="0.489*"/>
                            					<ColumnDefinition Width="0.511*"/>
                            				</Grid.ColumnDefinitions>
                            				<TextBox 
                            					TextWrapping="Wrap" 
                            					Style="{DynamicResource WatermarkedTextBox}" 
                            					Tag="Activité FR" 
                            					Text="{Binding SelectedActiCopy.SActiviteFR, Source={StaticResource vm}}" d:LayoutOverrides="VerticalAlignment, GridBox"/>
                            				<TextBox
                            					x:Name="tb_loc" 
                            					TextWrapping="Wrap" 
                            					Style="{DynamicResource WatermarkedTextBox}" 
                            					Tag="Activité NL" 
                            					Text="{Binding SelectedActiCopy.SActiviteNL, Source={StaticResource vm}}" d:LayoutOverrides="VerticalAlignment" Grid.Column="1" Margin="0,0,-0.112,0"/>
                            			</Grid>
                            			<DataGrid 
                            				x:Name="dtg_loc" 
                            				AutoGenerateColumns="False" 
                            				ItemsSource="{Binding ActiColl, Source={StaticResource vm}}" 
                            				SelectedItem="{Binding SelectedActi, Source={StaticResource vm}}" 
                            				SelectionChanged="dtg_loc_SelectionChanged" 
                            				CanUserAddRows="False" 
                            				CanUserDeleteRows="False" 
                            				IsReadOnly="True" 
                            				SelectionMode="Single"
                            				DockPanel.Dock="Top" FrozenColumnCount="1"
    						            >
                            				<DataGrid.Columns>
                            					<DataGridTemplateColumn DisplayIndex="0">
                            						<DataGridTemplateColumn.CellTemplate>
                            							<DataTemplate>
                            								<Grid>
                            									<Button  
                            										FontSize="10" Padding="0" x:Name="bt_editContact" Click="bt_editContact_Click">
                            										<Image Source="/ControlDo;component/Images/Edit16.png" />
                            									</Button>
                            								</Grid>
                            							</DataTemplate>
                            						</DataGridTemplateColumn.CellTemplate>
                            					</DataGridTemplateColumn>
                            					<DataGridTextColumn Binding="{Binding NIdLocalite}" Header="nIdLocalite" Visibility="Hidden" />
                            					<DataGridTextColumn Binding="{Binding SActiviteFR}" Header="Activité FR" />
                            					<DataGridTextColumn Binding="{Binding SActiviteNL}" Header="Activité NL" Width="200" />
                            				</DataGrid.Columns>                                 
                            			</DataGrid>
                            		</DockPanel>
                            	</Grid>
                            	
                            </DockPanel>
    				    </kb:Resizer>
    			    </Popup>
    			</Grid>
            </ToggleButton>
            
        </Grid>
    </UserControl>

    Le code behind :

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;
    using BibliDo.Classe;
    using System.Collections;
    using System.Windows.Media.Animation;
    using ControlDo.UC.ViewModels;
    using ControlDo.UC;
    using System.Windows.Controls.Primitives;
    using System.Timers;
    
    namespace ControlDo
    {
    	public partial class UCComboBoxActi : UserControl
    	{
            
            static VMUCCBActivite ressourceVM;
            public UCComboBoxActi()
    		{
                
    			this.InitializeComponent();
                ressourceVM = (VMUCCBActivite)FindResource("vm");
                
                this.Loaded += new RoutedEventHandler(View1_Loaded);
    		}
    
            void View1_Loaded(object sender, RoutedEventArgs e)
            {
                Window w = Window.GetWindow(pop);
                if (null != w)
                {
                    w.LocationChanged += delegate(object sender2, EventArgs args)
                    {
                        var offset = pop.HorizontalOffset;
                        pop.HorizontalOffset = offset + 1;
                        pop.HorizontalOffset = offset;
                    };
                    w.SizeChanged += delegate(object sender3, SizeChangedEventArgs e2)
                    {
                        var offset = pop.HorizontalOffset;
                        pop.HorizontalOffset = offset + 1;
                        pop.HorizontalOffset = offset;
                    };
                }
            }
            
            public object SelectedItemActiEnt
            {
                get { return (object)GetValue(SelectedItemEntProperty); }
                set { SetValue(SelectedItemEntProperty, value); }
            }
            public static readonly DependencyProperty SelectedItemEntProperty =
                DependencyProperty.Register("SelectedItemActiEnt", typeof(object),
                  typeof(UCComboBoxActi), new PropertyMetadata(OnEntPropChanged));
    
            private static void OnEntPropChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
            {
                ressourceVM.FilterActi = "";
                //(d as UCComboBoxActi).toggleButton.IsChecked = false;
                ressourceVM.SelectedEntCopy = (Entite)e.NewValue;
                
            }
    		private void dtg_loc_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
            {
                if (dtg_loc.SelectedItem != null)
                    dtg_loc.ScrollIntoView(dtg_loc.SelectedItem);
    			
    			if(ck_Activite.IsChecked == true)  ((Storyboard)FindResource("down")).Begin();
    			if(ck_supActi.IsChecked == true)  ((Storyboard)FindResource("DeleteHide")).Begin();
            }
            private void toggleButton_Checked(object sender, System.Windows.RoutedEventArgs e)
            {
                pop.IsOpen = true;
    			
    			
    			//if(ck_supActi.IsChecked == true)  ((Storyboard)FindResource("DeleteHide")).Begin();
    			
    			if (dtg_loc.SelectedItem != null)
                    dtg_loc.ScrollIntoView(dtg_loc.SelectedItem);
            }
    		private void bt_editContact_Click(object sender, RoutedEventArgs e)
            {
                ((Storyboard)FindResource("up")).Begin();
            }
    
    		private void LayoutRoot_LostFocus(object sender, System.Windows.RoutedEventArgs e)
    		{
    			if(pop.IsOpen == false)
    				toggleButton.IsChecked = false;
    				// TODO: Add event handler implementation here.
    		}
    
    
    		private void bt_deleteActivite_LostFocus(object sender, System.Windows.RoutedEventArgs e)
    		{
    			
    		}
    
    		private void popup_supprimer_LostFocus(object sender, System.Windows.RoutedEventArgs e)
    		{
                //if(popup_supprimer.IsOpen == false)
                //    bt_deleteActivite.IsChecked = false;
    		}
    
    		private void toggleButton_Click(object sender, System.Windows.RoutedEventArgs e)
    		{
    			if(ck_supActi.IsChecked == true)  ((Storyboard)FindResource("DeleteHide")).Begin();
    		}
        }
    }

    Le ViewModel :

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using GalaSoft.MvvmLight;
    using BibliDo.Classe;
    using System.ComponentModel;
    using System.Collections.ObjectModel;
    using System.Windows.Data;
    using System.Windows.Input;
    using GalaSoft.MvvmLight.Command;
    using System.Windows.Controls;
    using System.Windows;
    
    namespace ControlDo.UC.ViewModels
    {
    
        public class VMUCCBActivite : ViewModelBase
        {
            Factory facto = new Factory();
            public VMUCCBActivite()
            {
                actiCollView = CollectionViewSource.GetDefaultView(actiColl);
                actiCollView.Filter = o =>
                {
                    String sActiviteFR = null;
                    String sActiviteNL = null;
    
                    if (((Activite)o).SActiviteNL == null) sActiviteNL = "";
                    else sActiviteNL = ((Activite)o).SActiviteNL;
    
                    if (((Activite)o).SActiviteFR == null) sActiviteFR = "";
                    else sActiviteFR = ((Activite)o).SActiviteFR;
    
    
                    if (String.IsNullOrEmpty(FilterActi)) return true;
                    else
                    {
                        if (sActiviteNL.Contains(filterActi.ToLower())
                        || sActiviteFR.ToLower().Contains(FilterActi.ToLower())) return true;
                        else return false;
                    }
    
                };
    
            }
    
            ICollectionView actiCollView;
            ObservableCollection<Activite> actiColl = new ObservableCollection<Activite>();
            public ObservableCollection<Activite> ActiColl
            {
                get { return actiColl; }
                set { actiColl = value; RaisePropertyChanged("ActiColl"); }
            }
    
            String filterActi;
            public String FilterActi
            {
                get { return filterActi; }
                set
                {
                    if (value != filterActi)
                    {
                        filterActi = value;
                        flag = true;
                        actiCollView.Refresh();
                        flag = false;
                        RaisePropertyChanged("FilterActi");
                    }
                }
            }
    
            Activite selectedActi;
            public Activite SelectedActi
            {
                get { return selectedActi; }
                set
                {
                    if (flag == false)
                    {
                        //Ce test est effectué voir si une activité n'a pas été supprimé
                        if (value == null) selectedActi = null;
                        else
                        {
                            if (ActiColl.Where(x => x.NIdActivite == value.NIdActivite).FirstOrDefault() != null)
                                selectedActi = ActiColl.Where(x => x.NIdActivite == value.NIdActivite).FirstOrDefault();
                            else
                            {
                                if (SelectedEntCopy.SType == "G") selectedActi = new ActiGarage();
                                else selectedActi = new ActiClient();
                            }
    
                        }
    
                        if (SelectedEntCopy.SType == "G")
                        {
                            SelectedActiCopy = new ActiGarage(value);
                            SelectedEntCopy.Acti = new ActiGarage(value);
                        }
                        else
                        {
                            SelectedActiCopy = new ActiClient(value);
                            SelectedEntCopy.Acti = new ActiClient(value);
                        }
    
                        RaisePropertyChanged("SelectedActi");
                    }
                }
            }
    
            bool flag = false;
            private String type;
    
            Entite selectedEntCopy;
            public Entite SelectedEntCopy
            {
                get { return selectedEntCopy; }
                set
                {
                    selectedEntCopy = value;
    
                    if (type != selectedEntCopy.SType)
                    {
                        Activite[] lstActi = null;
                        actiColl.Clear();
    
                        if (selectedEntCopy.SType == "G") lstActi = (facto.getIActivite()).ListActiGarage();
                        else lstActi = (facto.getIActivite()).ListActiClient();
    
                        if (lstActi != null)
                            foreach (Activite acti in lstActi)
                                this.actiColl.Add(acti);
                        type = selectedEntCopy.SType;
                    }
    
                    SelectedActi = selectedEntCopy.Acti;
                    RaisePropertyChanged("SelectedEntCopy");
    
                }
            }
            
            Activite selectedActiCopy;
            public Activite SelectedActiCopy
            {
                get { return selectedActiCopy; }
                set { selectedActiCopy = value; RaisePropertyChanged("SelectedActiCopy"); }
            }
    
            private bool isAddActiviteMod;
            public bool IsAddActiviteMod
            {
                get { return isAddActiviteMod; }
                set { isAddActiviteMod = value; }
            }
    
            public ICommand SaveActivite { get { return new RelayCommand(SaveExecute, CanSaveExecute); } }
            bool CanSaveExecute() { return true; }
            void SaveExecute()
            {
                int id;
                if (IsAddActiviteMod == true)
                {
                    ActiColl.Add(selectedActiCopy);
                    SelectedActi = ActiColl[ActiColl.Count - 1];
    
                    SelectedActi.NIdActivite = (facto.getIActivite()).InsertActivite(SelectedActi);
                }
                else
                {
                    id = actiColl.IndexOf(SelectedActi);
    
                    if (SelectedEntCopy.SType == "G") ActiColl[id] = new ActiGarage(SelectedActiCopy);
                    else ActiColl[id] = new ActiClient(SelectedActiCopy); 
    
                    SelectedActi = actiColl[id];
                    
                    (facto.getIActivite()).UpdateActivite(SelectedActi);
    
                }
                IsAddActiviteMod = false;
            }
            public ICommand AddActivite { get { return new RelayCommand(AddExecute, CanAddExecute); } }
            bool CanAddExecute() { return true; }
            void AddExecute()
            {
                IsAddActiviteMod = true;
                if (SelectedEntCopy.SType == "G") SelectedActiCopy = new ActiGarage();
                else SelectedActiCopy = new ActiClient();
            }
    
            public ICommand RemoveActivite { get { return new RelayCommand(RemoveActiviteExecute, CanRemoveActiviteExecute); } }
            bool CanRemoveActiviteExecute() { return true; }
            void RemoveActiviteExecute()
            {
                
                    flag = true;
                    actiColl.Remove(SelectedActi);
                    (facto.getIActivite()).DeleteActivite(selectedActi);
                    if (SelectedEntCopy.SType == "G") selectedActi = new ActiGarage();
                    else selectedActi = new ActiClient();
    
                    RaisePropertyChanged("SelectedActi");
                    flag = false;
                
            }
            
        }
    }

    Pour ce UserControl, je me suis servi des références :

    Kent.Boogaart.Windows.Controls

    GalaSoft.MvvmLight.WPF4

    En espérant que ca puisse aider quelqu'un :-)

    • Marqué comme réponse Aurel Bera lundi 1 juillet 2013 08:18
    lundi 1 juillet 2013 08:09

Toutes les réponses

  • Bonjour,

    Pouvons-nous considérer que vous avez résolu votre problème avec les scénarios proposés ? Dans l'affirmative, pourriez-vous partager avec nous la solution, afin que d'autres personnes avec le même problème puissent profiter de cette solution ?

    Désormais, nous marquons les solutions proposées. N'hésitez pas à revenir et supprimer la réponse marquée si la solution n’est pas correcte. Merci !

    Cordialement,


    Aurel BERA, Microsoft
    Microsoft propose ce service gratuitement, dans le but d'aider les utilisateurs et d'élargir les connaissances générales liées aux produits et technologies Microsoft. Ce contenu est fourni "tel quel" et il n'implique aucune responsabilité de la part de Microsoft.

    lundi 1 juillet 2013 07:51
  • Désolé pour la lenteur, j'ai décidé de recrée moi même mon User Control :

    Le UserControl ( XAML) :

    <UserControl
    	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    	xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    	xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    	xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero"
        xmlns:local="clr-namespace:ControlDo"
        xmlns:ControlDo_Converter="clr-namespace:ControlDo.Converter"
    	xmlns:local_Views="clr-namespace:ControlDo.UC"
        xmlns:ViewModel="clr-namespace:ControlDo.UC.ViewModels"
        xmlns:views="clr-namespace:ControlDo.Views"
    	xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" 
        xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
        xmlns:System="clr-namespace:System;assembly=mscorlib" 
        mc:Ignorable="d"
    	x:Class="ControlDo.UCComboBoxActi"
    	x:Name="ComboBoxLocalite" 
    	Height="63" 
    	Width="237"
        >
    
        <!--<UserControl.DataContext>
            <ViewModel:VMUCCBLocalite x:Name="viewModel"/>
        </UserControl.DataContext>-->
    
        <UserControl.Resources>
            <local_Views:DatagridItemBehavior x:Key="DatagridItemBehavior"/>
            <ViewModel:VMUCCBActivite x:Key="vm" />
            
    		<ControlDo_Converter:IntToBool x:Key="IntToBool"/>
    		<Style x:Key="ComboBoxFocusVisual">
    			<Setter Property="Control.Template">
    				<Setter.Value>
    					<ControlTemplate>
    						<Rectangle Margin="4,4,21,4" SnapsToDevicePixels="true" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2"/>
    					</ControlTemplate>
    				</Setter.Value>
    			</Setter>
    		</Style>
    		<LinearGradientBrush x:Key="ButtonNormalBackground" EndPoint="0,1" StartPoint="0,0">
    			<GradientStop Color="#F3F3F3" Offset="0"/>
    			<GradientStop Color="#EBEBEB" Offset="0.5"/>
    			<GradientStop Color="#DDDDDD" Offset="0.5"/>
    			<GradientStop Color="#CDCDCD" Offset="1"/>
    		</LinearGradientBrush>
    		<SolidColorBrush x:Key="ButtonNormalBorder" Color="#FF707070"/>
    		<Geometry x:Key="DownArrowGeometry">M 0 0 L 3.5 4 L 7 0 Z</Geometry>
    		<Style x:Key="ComboBoxReadonlyToggleButton" TargetType="{x:Type ToggleButton}">
    			<Setter Property="OverridesDefaultStyle" Value="true"/>
    			<Setter Property="IsTabStop" Value="false"/>
    			<Setter Property="Focusable" Value="false"/>
    			<Setter Property="ClickMode" Value="Press"/>
    			<Setter Property="Template">
    				<Setter.Value>
    					<ControlTemplate TargetType="{x:Type ToggleButton}">
    						<Microsoft_Windows_Themes:ButtonChrome x:Name="Chrome" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderPressed="{TemplateBinding IsPressed}" SnapsToDevicePixels="true">
    							<Grid HorizontalAlignment="Right" Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}">
    								<Path x:Name="Arrow" Data="{StaticResource DownArrowGeometry}" Fill="Black" HorizontalAlignment="Center" Margin="3,1,0,0" VerticalAlignment="Center"/>
    							</Grid>
    						</Microsoft_Windows_Themes:ButtonChrome>
    						<ControlTemplate.Triggers>
    							<Trigger Property="IsChecked" Value="true">
    								<Setter Property="RenderPressed" TargetName="Chrome" Value="true"/>
    							</Trigger>
    							<Trigger Property="IsEnabled" Value="false">
    								<Setter Property="Fill" TargetName="Arrow" Value="#AFAFAF"/>
    							</Trigger>
    						</ControlTemplate.Triggers>
    					</ControlTemplate>
    				</Setter.Value>
    			</Setter>
    		</Style>
    		<LinearGradientBrush x:Key="TextBoxBorder" EndPoint="0,20" MappingMode="Absolute" StartPoint="0,0">
    			<GradientStop Color="#ABADB3" Offset="0.05"/>
    			<GradientStop Color="#E2E3EA" Offset="0.07"/>
    			<GradientStop Color="#E3E9EF" Offset="1"/>
    		</LinearGradientBrush>
    		<Style x:Key="ComboBoxEditableTextBox" TargetType="{x:Type TextBox}">
    			<Setter Property="OverridesDefaultStyle" Value="true"/>
    			<Setter Property="AllowDrop" Value="true"/>
    			<Setter Property="MinWidth" Value="0"/>
    			<Setter Property="MinHeight" Value="0"/>
    			<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
    			<Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/>
    			<Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
    			<Setter Property="Template">
    				<Setter.Value>
    					<ControlTemplate TargetType="{x:Type TextBox}">
    						<ScrollViewer x:Name="PART_ContentHost" Background="Transparent" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden"/>
    					</ControlTemplate>
    				</Setter.Value>
    			</Setter>
    		</Style>
    		<Style x:Key="ComboBoxToggleButton" TargetType="{x:Type ToggleButton}">
    			<Setter Property="OverridesDefaultStyle" Value="true"/>
    			<Setter Property="IsTabStop" Value="false"/>
    			<Setter Property="Focusable" Value="false"/>
    			<Setter Property="ClickMode" Value="Press"/>
    			<Setter Property="Template">
    				<Setter.Value>
    					<ControlTemplate TargetType="{x:Type ToggleButton}">
    						<Microsoft_Windows_Themes:ButtonChrome x:Name="Chrome" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderPressed="{TemplateBinding IsPressed}" RoundCorners="false" SnapsToDevicePixels="true" Width="{DynamicResource {x:Static SystemParameters.VerticalScrollBarWidthKey}}">
    							<Path x:Name="Arrow" Data="{StaticResource DownArrowGeometry}" Fill="Black" HorizontalAlignment="Center" Margin="0,1,0,0" VerticalAlignment="Center"/>
    						</Microsoft_Windows_Themes:ButtonChrome>
    						<ControlTemplate.Triggers>
    							<Trigger Property="IsChecked" Value="true">
    								<Setter Property="RenderPressed" TargetName="Chrome" Value="true"/>
    							</Trigger>
    							<Trigger Property="IsEnabled" Value="false">
    								<Setter Property="Fill" TargetName="Arrow" Value="#AFAFAF"/>
    							</Trigger>
    						</ControlTemplate.Triggers>
    					</ControlTemplate>
    				</Setter.Value>
    			</Setter>
    		</Style>
    		<ControlTemplate x:Key="ComboBoxEditableTemplate" TargetType="{x:Type ComboBox}">
    			<Grid x:Name="Placement" SnapsToDevicePixels="true">
    				<Grid.ColumnDefinitions>
    					<ColumnDefinition Width="*"/>
    					<ColumnDefinition Width="Auto"/>
    				</Grid.ColumnDefinitions>
    				<Popup x:Name="PART_Popup" AllowsTransparency="true" Grid.ColumnSpan="2" IsOpen="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}" PopupAnimation="{DynamicResource {x:Static SystemParameters.ComboBoxPopupAnimationKey}}" Placement="Bottom">
    					<Microsoft_Windows_Themes:SystemDropShadowChrome x:Name="Shdw" Color="Transparent" MaxHeight="{TemplateBinding MaxDropDownHeight}" MinWidth="{Binding ActualWidth, ElementName=Placement}">
    						<Border x:Name="DropDownBorder" BorderBrush="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" BorderThickness="1" Background="{DynamicResource {x:Static SystemColors.WindowBrushKey}}">
    							<ScrollViewer x:Name="DropDownScrollViewer">
    								<Grid RenderOptions.ClearTypeHint="Enabled">
    									<Canvas HorizontalAlignment="Left" Height="0" VerticalAlignment="Top" Width="0">
    										<Rectangle x:Name="OpaqueRect" Fill="{Binding Background, ElementName=DropDownBorder}" Height="{Binding ActualHeight, ElementName=DropDownBorder}" Width="{Binding ActualWidth, ElementName=DropDownBorder}"/>
    									</Canvas>
    									<ItemsPresenter x:Name="ItemsPresenter" KeyboardNavigation.DirectionalNavigation="Contained" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
    								</Grid>
    							</ScrollViewer>
    						</Border>
    					</Microsoft_Windows_Themes:SystemDropShadowChrome>
    				</Popup>
    				<Microsoft_Windows_Themes:ListBoxChrome x:Name="Border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Grid.ColumnSpan="2" RenderMouseOver="{TemplateBinding IsMouseOver}" RenderFocused="{TemplateBinding IsKeyboardFocusWithin}"/>
    				<TextBox x:Name="PART_EditableTextBox" HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" IsReadOnly="{Binding IsReadOnly, RelativeSource={RelativeSource TemplatedParent}}" Margin="{TemplateBinding Padding}" Style="{StaticResource ComboBoxEditableTextBox}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"/>
    				<ToggleButton Grid.Column="1" IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}" Style="{StaticResource ComboBoxToggleButton}"/>
    			</Grid>
    			<ControlTemplate.Triggers>
    				<Trigger Property="IsKeyboardFocusWithin" Value="true">
    					<Setter Property="Foreground" Value="Black"/>
    				</Trigger>
    				<Trigger Property="IsDropDownOpen" Value="true">
    					<Setter Property="RenderFocused" TargetName="Border" Value="true"/>
    				</Trigger>
    				<Trigger Property="HasItems" Value="false">
    					<Setter Property="Height" TargetName="DropDownBorder" Value="95"/>
    				</Trigger>
    				<Trigger Property="IsEnabled" Value="false">
    					<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
    					<Setter Property="Background" Value="#FFF4F4F4"/>
    				</Trigger>
    				<Trigger Property="IsGrouping" Value="true">
    					<Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
    				</Trigger>
    				<Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="true">
    					<Setter Property="Margin" TargetName="Shdw" Value="0,0,5,5"/>
    					<Setter Property="Color" TargetName="Shdw" Value="#71000000"/>
    				</Trigger>
    				<Trigger Property="ScrollViewer.CanContentScroll" SourceName="DropDownScrollViewer" Value="false">
    					<Setter Property="Canvas.Top" TargetName="OpaqueRect" Value="{Binding VerticalOffset, ElementName=DropDownScrollViewer}"/>
    					<Setter Property="Canvas.Left" TargetName="OpaqueRect" Value="{Binding HorizontalOffset, ElementName=DropDownScrollViewer}"/>
    				</Trigger>
    			</ControlTemplate.Triggers>
    		</ControlTemplate>
    		<Style x:Key="WatermarkedTextBox" >
    			<Setter Property="Control.Template" >
    				<Setter.Value>
    					<ControlTemplate TargetType="{x:Type TextBox}" >
    						<!-- Template derived from Default TextBoxBase. -->
    
    		
    		
    	<!-- Added the Label InternalWatermarkLabel together with the surrounding Grid. -->
    						<Grid>
    							<Microsoft_Windows_Themes:ListBoxChrome x:Name="Bd"
    								Background="{TemplateBinding Panel.Background}" 
    								BorderBrush="{TemplateBinding Border.BorderBrush}"
    								BorderThickness="{TemplateBinding Border.BorderThickness}"
    								RenderMouseOver="{TemplateBinding IsMouseOver}" 
    								RenderFocused="{TemplateBinding IsKeyboardFocusWithin}" 
    								SnapsToDevicePixels="True">
    								<ScrollViewer x:Name="PART_ContentHost"
    									SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                              />
    							</Microsoft_Windows_Themes:ListBoxChrome>
    							<Label x:Name="InternalWatermarkLabel" 
    								Content="{TemplateBinding Tag}" 
    								Visibility="Collapsed" Focusable="False"
    								Foreground="Silver"
    								Background="Transparent"
                                   />
    						</Grid>
    						<ControlTemplate.Triggers>
                            <!-- The multitrigger is responsible for showing and hiding the watermark. -->
    							<MultiTrigger>
    								<MultiTrigger.Conditions>
    									<Condition Property="IsFocused" Value="False" />
    									<Condition Property="Text" Value="" />
    								</MultiTrigger.Conditions>
    								<Setter Property="Visibility" TargetName="InternalWatermarkLabel"
    									Value="Visible" />
    							</MultiTrigger>
                            <!-- This trigger mimics the default behavior. -->
    							<Trigger Property="IsEnabled" Value="False" >
    								<Setter Property="Panel.Background" TargetName="Bd"
    									Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" />
    								<Setter Property="TextElement.Foreground"
    									Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
    							</Trigger>
    						</ControlTemplate.Triggers>
    					</ControlTemplate>
    				</Setter.Value>
    			</Setter>
    		</Style>
    
    
            <Storyboard x:Key="RowToAnimateDown">
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="bt_addActivite">
                    <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                    <EasingDoubleKeyFrame KeyTime="0:0:1" Value="29"/>
                </DoubleAnimationUsingKeyFrames>
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="bt_deleteActivite">
                    <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                    <EasingDoubleKeyFrame KeyTime="0:0:1" Value="29"/>
                </DoubleAnimationUsingKeyFrames>
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="bt_saveActivite">
                    <EasingDoubleKeyFrame KeyTime="0" Value="29"/>
                    <EasingDoubleKeyFrame KeyTime="0:0:1" Value="0"/>
                </DoubleAnimationUsingKeyFrames>
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="bt_cancelActivite">
                    <EasingDoubleKeyFrame KeyTime="0" Value="29"/>
                    <EasingDoubleKeyFrame KeyTime="0:0:1" Value="0"/>
                </DoubleAnimationUsingKeyFrames>
                <BooleanAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.IsEnabled)" Storyboard.TargetName="grid_Localite2_2">
                    <DiscreteBooleanKeyFrame KeyTime="0" Value="False"/>
                    <DiscreteBooleanKeyFrame KeyTime="0:0:1" Value="True"/>
                </BooleanAnimationUsingKeyFrames>
                <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(ToggleButton.IsChecked)" Storyboard.TargetName="ck_Activite">
                    <DiscreteObjectKeyFrame KeyTime="0">
                        <DiscreteObjectKeyFrame.Value>
                            <System:Boolean>True</System:Boolean>
                        </DiscreteObjectKeyFrame.Value>
                    </DiscreteObjectKeyFrame>
                    <DiscreteObjectKeyFrame KeyTime="0:0:0.1">
                        <DiscreteObjectKeyFrame.Value>
                            <System:Boolean>False</System:Boolean>
                        </DiscreteObjectKeyFrame.Value>
                    </DiscreteObjectKeyFrame>
                </ObjectAnimationUsingKeyFrames>
            </Storyboard>
            <Storyboard x:Key="RowToAnimationUp">
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="bt_addActivite">
                    <EasingDoubleKeyFrame KeyTime="0:0:1" Value="0"/>
                </DoubleAnimationUsingKeyFrames>
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="bt_deleteActivite">
                    <EasingDoubleKeyFrame KeyTime="0:0:1" Value="0"/>
                </DoubleAnimationUsingKeyFrames>
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="bt_saveActivite">
                    <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                    <EasingDoubleKeyFrame KeyTime="0:0:1" Value="29"/>
                </DoubleAnimationUsingKeyFrames>
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="bt_cancelActivite">
                    <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                    <EasingDoubleKeyFrame KeyTime="0:0:1" Value="29"/>
                </DoubleAnimationUsingKeyFrames>
                <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(ToggleButton.IsChecked)" Storyboard.TargetName="ck_Activite">
                    <DiscreteObjectKeyFrame KeyTime="0">
                        <DiscreteObjectKeyFrame.Value>
                            <System:Boolean>False</System:Boolean>
                        </DiscreteObjectKeyFrame.Value>
                    </DiscreteObjectKeyFrame>
                    <DiscreteObjectKeyFrame KeyTime="0:0:0.1">
                        <DiscreteObjectKeyFrame.Value>
                            <System:Boolean>True</System:Boolean>
                        </DiscreteObjectKeyFrame.Value>
                    </DiscreteObjectKeyFrame>
                </ObjectAnimationUsingKeyFrames>
            </Storyboard>
            <Storyboard x:Key="up">
            	<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="grid">
            		<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
            		<EasingDoubleKeyFrame KeyTime="0:0:1" Value="30"/>
            	</DoubleAnimationUsingKeyFrames>
    			<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="bt_addActivite">
                    <EasingDoubleKeyFrame KeyTime="0:0:1" Value="0"/>
                </DoubleAnimationUsingKeyFrames>
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="bt_deleteActivite">
                    <EasingDoubleKeyFrame KeyTime="0:0:1" Value="0"/>
                </DoubleAnimationUsingKeyFrames>
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="bt_saveActivite">
                    <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                    <EasingDoubleKeyFrame KeyTime="0:0:1" Value="29"/>
                </DoubleAnimationUsingKeyFrames>
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="bt_cancelActivite">
                    <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                    <EasingDoubleKeyFrame KeyTime="0:0:1" Value="29"/>
                </DoubleAnimationUsingKeyFrames>
    			<BooleanAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.IsEnabled)" Storyboard.TargetName="grid_Localite2_2">
                    <DiscreteBooleanKeyFrame KeyTime="0" Value="False"/>
                    <DiscreteBooleanKeyFrame KeyTime="0:0:1" Value="True"/>
                </BooleanAnimationUsingKeyFrames>
                <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(ToggleButton.IsChecked)" Storyboard.TargetName="ck_Activite">
                    <DiscreteObjectKeyFrame KeyTime="0">
                        <DiscreteObjectKeyFrame.Value>
                            <System:Boolean>False</System:Boolean>
                        </DiscreteObjectKeyFrame.Value>
                    </DiscreteObjectKeyFrame>
                    <DiscreteObjectKeyFrame KeyTime="0:0:0.1">
                        <DiscreteObjectKeyFrame.Value>
                            <System:Boolean>True</System:Boolean>
                        </DiscreteObjectKeyFrame.Value>
                    </DiscreteObjectKeyFrame>
                </ObjectAnimationUsingKeyFrames>
            </Storyboard>
            <Storyboard x:Key="down">
            	<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="grid">
            		<EasingDoubleKeyFrame KeyTime="0" Value="30"/>
            		<EasingDoubleKeyFrame KeyTime="0:0:1" Value="0"/>
            	</DoubleAnimationUsingKeyFrames>
    			<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="bt_addActivite">
                    <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                    <EasingDoubleKeyFrame KeyTime="0:0:1" Value="29"/>
                </DoubleAnimationUsingKeyFrames>
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="bt_deleteActivite">
                    <EasingDoubleKeyFrame KeyTime="0" Value="0"/>
                    <EasingDoubleKeyFrame KeyTime="0:0:1" Value="29"/>
                </DoubleAnimationUsingKeyFrames>
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="bt_saveActivite">
                    <EasingDoubleKeyFrame KeyTime="0" Value="29"/>
                    <EasingDoubleKeyFrame KeyTime="0:0:1" Value="0"/>
                </DoubleAnimationUsingKeyFrames>
                <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Height)" Storyboard.TargetName="bt_cancelActivite">
                    <EasingDoubleKeyFrame KeyTime="0" Value="29"/>
                    <EasingDoubleKeyFrame KeyTime="0:0:1" Value="0"/>
                </DoubleAnimationUsingKeyFrames>
                <BooleanAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.IsEnabled)" Storyboard.TargetName="grid_Localite2_2">
                    <DiscreteBooleanKeyFrame KeyTime="0" Value="False"/>
                    <DiscreteBooleanKeyFrame KeyTime="0:0:1" Value="True"/>
                </BooleanAnimationUsingKeyFrames>
                <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(ToggleButton.IsChecked)" Storyboard.TargetName="ck_Activite">
                    <DiscreteObjectKeyFrame KeyTime="0">
                        <DiscreteObjectKeyFrame.Value>
                            <System:Boolean>True</System:Boolean>
                        </DiscreteObjectKeyFrame.Value>
                    </DiscreteObjectKeyFrame>
                    <DiscreteObjectKeyFrame KeyTime="0:0:0.1">
                        <DiscreteObjectKeyFrame.Value>
                            <System:Boolean>False</System:Boolean>
                        </DiscreteObjectKeyFrame.Value>
                    </DiscreteObjectKeyFrame>
                </ObjectAnimationUsingKeyFrames>
            </Storyboard>
            <Storyboard x:Key="ToggleButtonCheck">
            	<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(ToggleButton.IsChecked)" Storyboard.TargetName="toggleButton">
            		<DiscreteObjectKeyFrame KeyTime="0">
            			<DiscreteObjectKeyFrame.Value>
            				<System:Boolean>False</System:Boolean>
            			</DiscreteObjectKeyFrame.Value>
            		</DiscreteObjectKeyFrame>
            		<DiscreteObjectKeyFrame KeyTime="0:0:0.1">
            			<DiscreteObjectKeyFrame.Value>
            				<System:Boolean>True</System:Boolean>
            			</DiscreteObjectKeyFrame.Value>
            		</DiscreteObjectKeyFrame>
            	</ObjectAnimationUsingKeyFrames>
            </Storyboard>
            <Storyboard x:Key="ToggleButtonUnCheck">
            	<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(ToggleButton.IsChecked)" Storyboard.TargetName="toggleButton">
            		<DiscreteObjectKeyFrame KeyTime="0">
            			<DiscreteObjectKeyFrame.Value>
            				<System:Boolean>True</System:Boolean>
            			</DiscreteObjectKeyFrame.Value>
            		</DiscreteObjectKeyFrame>
            		<DiscreteObjectKeyFrame KeyTime="0:0:0.1">
            			<DiscreteObjectKeyFrame.Value>
            				<System:Boolean>False</System:Boolean>
            			</DiscreteObjectKeyFrame.Value>
            		</DiscreteObjectKeyFrame>
            	</ObjectAnimationUsingKeyFrames>
            </Storyboard>
            <Storyboard x:Key="popupDeleteOpen">
            	<BooleanAnimationUsingKeyFrames Storyboard.TargetProperty="(Popup.IsOpen)" Storyboard.TargetName="popup_supprimer">
            		<DiscreteBooleanKeyFrame KeyTime="0" Value="False"/>
            		<DiscreteBooleanKeyFrame KeyTime="0:0:0.1" Value="True"/>
            	</BooleanAnimationUsingKeyFrames>
            </Storyboard>
            <Storyboard x:Key="popupDeleteClose">
            	<BooleanAnimationUsingKeyFrames Storyboard.TargetProperty="(Popup.IsOpen)" Storyboard.TargetName="popup_supprimer">
            		<DiscreteBooleanKeyFrame KeyTime="0" Value="True"/>
            		<DiscreteBooleanKeyFrame KeyTime="0:0:0.1" Value="False"/>
            	</BooleanAnimationUsingKeyFrames>
            </Storyboard>
            <Storyboard x:Key="DeleteShow">
            	<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Width)" Storyboard.TargetName="grid1">
            		<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
            		<EasingDoubleKeyFrame KeyTime="0:0:0.1" Value="300"/>
            	</DoubleAnimationUsingKeyFrames>
            	<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(ToggleButton.IsChecked)" Storyboard.TargetName="ck_supActi">
            		<DiscreteObjectKeyFrame KeyTime="0">
            			<DiscreteObjectKeyFrame.Value>
            				<System:Boolean>False</System:Boolean>
            			</DiscreteObjectKeyFrame.Value>
            		</DiscreteObjectKeyFrame>
            		<DiscreteObjectKeyFrame KeyTime="0:0:0.1">
            			<DiscreteObjectKeyFrame.Value>
            				<System:Boolean>True</System:Boolean>
            			</DiscreteObjectKeyFrame.Value>
            		</DiscreteObjectKeyFrame>
            	</ObjectAnimationUsingKeyFrames>
            </Storyboard>
            <Storyboard x:Key="DeleteHide">
            	<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Width)" Storyboard.TargetName="grid1">
            		<EasingDoubleKeyFrame KeyTime="0" Value="300"/>
            		<EasingDoubleKeyFrame KeyTime="0:0:0.1" Value="0"/>
            	</DoubleAnimationUsingKeyFrames>
            	<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(ToggleButton.IsChecked)" Storyboard.TargetName="ck_supActi">
            		<DiscreteObjectKeyFrame KeyTime="0">
            			<DiscreteObjectKeyFrame.Value>
            				<System:Boolean>True</System:Boolean>
            			</DiscreteObjectKeyFrame.Value>
            		</DiscreteObjectKeyFrame>
            		<DiscreteObjectKeyFrame KeyTime="0:0:0.1">
            			<DiscreteObjectKeyFrame.Value>
            				<System:Boolean>False</System:Boolean>
            			</DiscreteObjectKeyFrame.Value>
            		</DiscreteObjectKeyFrame>
            	</ObjectAnimationUsingKeyFrames>
            </Storyboard>
    
        </UserControl.Resources>
    	<UserControl.Triggers>
    		<EventTrigger RoutedEvent="ButtonBase.Click" SourceName="bt_addActivite">
    			<BeginStoryboard x:Name="RowToAnimationUp_BeginStoryboard" Storyboard="{StaticResource up}"/>
    		</EventTrigger>
    		<EventTrigger RoutedEvent="ButtonBase.Click" SourceName="bt_cancelActivite">
    			<BeginStoryboard x:Name="down_BeginStoryboard" Storyboard="{StaticResource down}"/>
    		</EventTrigger>
    		<EventTrigger RoutedEvent="ButtonBase.Click" SourceName="bt_saveActivite">
    			<BeginStoryboard x:Name="down_BeginStoryboard2" Storyboard="{StaticResource down}"/>
    		</EventTrigger>
    		<EventTrigger RoutedEvent="ButtonBase.Click" SourceName="bt_deleteActivite">
    			<BeginStoryboard x:Name="DeleteShow_BeginStoryboard" Storyboard="{StaticResource DeleteShow}"/>
    		</EventTrigger>
    		<EventTrigger RoutedEvent="ButtonBase.Click" SourceName="bt_supActiOui">
    			<BeginStoryboard x:Name="DeleteShow_BeginStoryboard1" Storyboard="{StaticResource DeleteHide}"/>
    		</EventTrigger>
    		<EventTrigger RoutedEvent="ButtonBase.Click" SourceName="bt_supActiNon">
    			<BeginStoryboard x:Name="DeleteHide_BeginStoryboard" Storyboard="{StaticResource DeleteHide}"/>
    		</EventTrigger>
        </UserControl.Triggers>
    
    	<Grid x:Name="LayoutRoot" 
              LostFocus="LayoutRoot_LostFocus">
    		<Grid.RowDefinitions>
    			<RowDefinition Height="0.968*"/>
    			<RowDefinition Height="0.032*"/>
    		</Grid.RowDefinitions>
                
            <ToggleButton 
                x:Name="toggleButton" 
                Grid.RowSpan="2" 
                Checked="toggleButton_Checked" 
                HorizontalContentAlignment="Left" 
                Click="toggleButton_Click" 
                >
            	<Grid Width="229" Margin="0">
            		<TextBlock 
    					x:Name="tb_cp" 
    					TextWrapping="Wrap" 
    					Text="{Binding SelectedActi.SActiviteFR, Source={StaticResource vm}, Mode=OneWay}" 
    					/>
                    <Popup 
    				    x:Name="pop" 
    				    PlacementTarget="{Binding ElementName=toggleButton, Mode=OneWay}" 
    				    StaysOpen="False"
    					Margin="0,0,177.334,0" 
    				    >
    
                        <!--StaysOpen="False"  IsOpen="{Binding IsChecked, ElementName=toggleButton}" -->
                        <kb:Resizer xmlns:kb="http://kent.boogaart/controls" Height="330" Width="430.909"  >
                            <DockPanel x:Name="DockPanel" Background="Black">
                            	<Grid x:Name="grid1" DockPanel.Dock="Right" Width="0">
                            		<Grid.Background>
                            			<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                            				<GradientStop Color="Black" Offset="1"/>
                            				<GradientStop Color="White"/>
                            			</LinearGradientBrush>
                            		</Grid.Background>
                            		<Button 
    									x:Name="bt_supActiOui" 
    									Margin="20.591,0,0,114.5" 
    									HorizontalAlignment="Left" 
    									Width="124.5" 
    									Height="36" 
    									VerticalAlignment="Bottom" 
    									Command="{Binding RemoveActivite, Source={StaticResource vm}}" 
    									>
                            			<DockPanel>
    										<TextBlock Text="Oui" DockPanel.Dock="Right" VerticalAlignment="Center" Margin="10,0,0,0"/>
    										<Image Height="28" Source="/ControlDo;component/Images/Accept48.png" Stretch="Fill" Width="27"/>
    									</DockPanel>
                            			
                            		</Button>
                            		<Button x:Name="bt_supActiNon" Margin="149.091,0,26.409,114.5" Height="36" VerticalAlignment="Bottom">
                            			<DockPanel>
    										<TextBlock Text="Non" DockPanel.Dock="Right" VerticalAlignment="Center" Margin="10,0,0,0"/>
    										<Image Height="24" Source="/ControlDo;component/Images/Cancel48.png" Stretch="Fill" Width="26.333"/>
    									</DockPanel>
                            		</Button>
                            		<TextBlock Height="48" Margin="20.591,108,26.409,0" TextWrapping="Wrap" Text="Etes-vous sûr de vouloir supprimer cette localité ? " VerticalAlignment="Top" HorizontalAlignment="Center"/>
                            		<Image Height="48" Margin="116.591,30,135.409,0" Source="/ControlDo;component/Images/Alert48.png" Stretch="Fill" VerticalAlignment="Top"/>
                            		<CheckBox x:Name="ck_supActi" Content="CheckBox" Height="30" Margin="75.091,0,141.909,51" VerticalAlignment="Bottom" Visibility="Hidden"/>
                            	</Grid>
    							<Grid x:Name="grid2">
                            		<TextBox 
                            			Height="29" 
                            			TextWrapping="Wrap" 
                            			Text="{Binding FilterActi, Mode=TwoWay, Source={StaticResource vm}, UpdateSourceTrigger=PropertyChanged}" 
                            			VerticalAlignment="Top" 
                            			Style="{DynamicResource WatermarkedTextBox}" 
                            			Tag="Recherche"/>
                            		<StackPanel Orientation="Vertical" x:Name="grid_Localite2_2" Opacity="1" Width="34.569" Margin="0,29,0,0" HorizontalAlignment="Right" d:LayoutOverrides="Width">
                        							
                            			<StackPanel.Background>
                            				<LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
                            					<GradientStop Color="White" Offset="0" />
                            					<GradientStop Color="#FFBABABA" Offset="1" />
                            				</LinearGradientBrush>
                            			</StackPanel.Background>
                            			<Button 
                            				Command="{Binding AddActivite, Source={StaticResource vm}}" 
                            				Height="29.032" 
                            				x:Name="bt_addActivite" 
                            				VerticalAlignment="Bottom" >
                            				<Image 
                            					Source="/ControlDo;component/Images/Add48.png" 
                            					Height="16.532" 
                            					Width="14.032"/>
                            			</Button>
                            			<Button 
                            				
                            				Height="29.032" 
                            				x:Name="bt_deleteActivite" 
                            				VerticalAlignment="Bottom" 
                            				IsEnabled="{Binding SelectedIndex, Converter={StaticResource IntToBool}, ElementName=dataGrid3}" HorizontalAlignment="Left" Width="34.569" >
                            				
                            					<Image 
                            						Source="/ControlDo;component/Images/Delete48.png" 
                            						Width="14" />
                            				
                            			</Button>
                            			<Button 
                            				Command="{Binding SaveActivite, Source={StaticResource vm}}" 
                            				Height="0"  
                            				Margin="0,0,0,0" 
                            				x:Name="bt_saveActivite" 
                            				VerticalAlignment="Bottom"  
                            				HorizontalAlignment="Left" 
                            				Width="34.569" >
                            				<Image 
                            					Source="/ControlDo;component/Images/Save48.png" 
                            					Width="14"/>
                            			</Button>
                            			<Button 
                            				Command="{Binding CancelActivite, Source={StaticResource vm}}" 
                            				Height="0"  
                            				Margin="0,0,0,0" 
                            				x:Name="bt_cancelActivite" 
                            				VerticalAlignment="Bottom" 
                            				d:LayoutOverrides="HorizontalAlignment, HorizontalMargin">
                            				<Image 
                            					Source="/ControlDo;component/Images/Cancel48.png" 
                            					Width="14" />
                            			</Button>
                            			<CheckBox 
                            				x:Name="ck_Activite" 
                            				Content="" 
                            				HorizontalContentAlignment="Center" 
                            				VerticalContentAlignment="Center"  
                            				Visibility="Hidden" />
                            		</StackPanel>
                            		<DockPanel Margin="0,29,34.569,0" Background="#FFE5ACAC">
                            			<Grid x:Name="grid" DockPanel.Dock="Bottom" Height="0">
                            				<Grid.ColumnDefinitions>
                            					<ColumnDefinition Width="0.489*"/>
                            					<ColumnDefinition Width="0.511*"/>
                            				</Grid.ColumnDefinitions>
                            				<TextBox 
                            					TextWrapping="Wrap" 
                            					Style="{DynamicResource WatermarkedTextBox}" 
                            					Tag="Activité FR" 
                            					Text="{Binding SelectedActiCopy.SActiviteFR, Source={StaticResource vm}}" d:LayoutOverrides="VerticalAlignment, GridBox"/>
                            				<TextBox
                            					x:Name="tb_loc" 
                            					TextWrapping="Wrap" 
                            					Style="{DynamicResource WatermarkedTextBox}" 
                            					Tag="Activité NL" 
                            					Text="{Binding SelectedActiCopy.SActiviteNL, Source={StaticResource vm}}" d:LayoutOverrides="VerticalAlignment" Grid.Column="1" Margin="0,0,-0.112,0"/>
                            			</Grid>
                            			<DataGrid 
                            				x:Name="dtg_loc" 
                            				AutoGenerateColumns="False" 
                            				ItemsSource="{Binding ActiColl, Source={StaticResource vm}}" 
                            				SelectedItem="{Binding SelectedActi, Source={StaticResource vm}}" 
                            				SelectionChanged="dtg_loc_SelectionChanged" 
                            				CanUserAddRows="False" 
                            				CanUserDeleteRows="False" 
                            				IsReadOnly="True" 
                            				SelectionMode="Single"
                            				DockPanel.Dock="Top" FrozenColumnCount="1"
    						            >
                            				<DataGrid.Columns>
                            					<DataGridTemplateColumn DisplayIndex="0">
                            						<DataGridTemplateColumn.CellTemplate>
                            							<DataTemplate>
                            								<Grid>
                            									<Button  
                            										FontSize="10" Padding="0" x:Name="bt_editContact" Click="bt_editContact_Click">
                            										<Image Source="/ControlDo;component/Images/Edit16.png" />
                            									</Button>
                            								</Grid>
                            							</DataTemplate>
                            						</DataGridTemplateColumn.CellTemplate>
                            					</DataGridTemplateColumn>
                            					<DataGridTextColumn Binding="{Binding NIdLocalite}" Header="nIdLocalite" Visibility="Hidden" />
                            					<DataGridTextColumn Binding="{Binding SActiviteFR}" Header="Activité FR" />
                            					<DataGridTextColumn Binding="{Binding SActiviteNL}" Header="Activité NL" Width="200" />
                            				</DataGrid.Columns>                                 
                            			</DataGrid>
                            		</DockPanel>
                            	</Grid>
                            	
                            </DockPanel>
    				    </kb:Resizer>
    			    </Popup>
    			</Grid>
            </ToggleButton>
            
        </Grid>
    </UserControl>

    Le code behind :

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Data;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Imaging;
    using System.Windows.Navigation;
    using System.Windows.Shapes;
    using BibliDo.Classe;
    using System.Collections;
    using System.Windows.Media.Animation;
    using ControlDo.UC.ViewModels;
    using ControlDo.UC;
    using System.Windows.Controls.Primitives;
    using System.Timers;
    
    namespace ControlDo
    {
    	public partial class UCComboBoxActi : UserControl
    	{
            
            static VMUCCBActivite ressourceVM;
            public UCComboBoxActi()
    		{
                
    			this.InitializeComponent();
                ressourceVM = (VMUCCBActivite)FindResource("vm");
                
                this.Loaded += new RoutedEventHandler(View1_Loaded);
    		}
    
            void View1_Loaded(object sender, RoutedEventArgs e)
            {
                Window w = Window.GetWindow(pop);
                if (null != w)
                {
                    w.LocationChanged += delegate(object sender2, EventArgs args)
                    {
                        var offset = pop.HorizontalOffset;
                        pop.HorizontalOffset = offset + 1;
                        pop.HorizontalOffset = offset;
                    };
                    w.SizeChanged += delegate(object sender3, SizeChangedEventArgs e2)
                    {
                        var offset = pop.HorizontalOffset;
                        pop.HorizontalOffset = offset + 1;
                        pop.HorizontalOffset = offset;
                    };
                }
            }
            
            public object SelectedItemActiEnt
            {
                get { return (object)GetValue(SelectedItemEntProperty); }
                set { SetValue(SelectedItemEntProperty, value); }
            }
            public static readonly DependencyProperty SelectedItemEntProperty =
                DependencyProperty.Register("SelectedItemActiEnt", typeof(object),
                  typeof(UCComboBoxActi), new PropertyMetadata(OnEntPropChanged));
    
            private static void OnEntPropChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
            {
                ressourceVM.FilterActi = "";
                //(d as UCComboBoxActi).toggleButton.IsChecked = false;
                ressourceVM.SelectedEntCopy = (Entite)e.NewValue;
                
            }
    		private void dtg_loc_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
            {
                if (dtg_loc.SelectedItem != null)
                    dtg_loc.ScrollIntoView(dtg_loc.SelectedItem);
    			
    			if(ck_Activite.IsChecked == true)  ((Storyboard)FindResource("down")).Begin();
    			if(ck_supActi.IsChecked == true)  ((Storyboard)FindResource("DeleteHide")).Begin();
            }
            private void toggleButton_Checked(object sender, System.Windows.RoutedEventArgs e)
            {
                pop.IsOpen = true;
    			
    			
    			//if(ck_supActi.IsChecked == true)  ((Storyboard)FindResource("DeleteHide")).Begin();
    			
    			if (dtg_loc.SelectedItem != null)
                    dtg_loc.ScrollIntoView(dtg_loc.SelectedItem);
            }
    		private void bt_editContact_Click(object sender, RoutedEventArgs e)
            {
                ((Storyboard)FindResource("up")).Begin();
            }
    
    		private void LayoutRoot_LostFocus(object sender, System.Windows.RoutedEventArgs e)
    		{
    			if(pop.IsOpen == false)
    				toggleButton.IsChecked = false;
    				// TODO: Add event handler implementation here.
    		}
    
    
    		private void bt_deleteActivite_LostFocus(object sender, System.Windows.RoutedEventArgs e)
    		{
    			
    		}
    
    		private void popup_supprimer_LostFocus(object sender, System.Windows.RoutedEventArgs e)
    		{
                //if(popup_supprimer.IsOpen == false)
                //    bt_deleteActivite.IsChecked = false;
    		}
    
    		private void toggleButton_Click(object sender, System.Windows.RoutedEventArgs e)
    		{
    			if(ck_supActi.IsChecked == true)  ((Storyboard)FindResource("DeleteHide")).Begin();
    		}
        }
    }

    Le ViewModel :

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using GalaSoft.MvvmLight;
    using BibliDo.Classe;
    using System.ComponentModel;
    using System.Collections.ObjectModel;
    using System.Windows.Data;
    using System.Windows.Input;
    using GalaSoft.MvvmLight.Command;
    using System.Windows.Controls;
    using System.Windows;
    
    namespace ControlDo.UC.ViewModels
    {
    
        public class VMUCCBActivite : ViewModelBase
        {
            Factory facto = new Factory();
            public VMUCCBActivite()
            {
                actiCollView = CollectionViewSource.GetDefaultView(actiColl);
                actiCollView.Filter = o =>
                {
                    String sActiviteFR = null;
                    String sActiviteNL = null;
    
                    if (((Activite)o).SActiviteNL == null) sActiviteNL = "";
                    else sActiviteNL = ((Activite)o).SActiviteNL;
    
                    if (((Activite)o).SActiviteFR == null) sActiviteFR = "";
                    else sActiviteFR = ((Activite)o).SActiviteFR;
    
    
                    if (String.IsNullOrEmpty(FilterActi)) return true;
                    else
                    {
                        if (sActiviteNL.Contains(filterActi.ToLower())
                        || sActiviteFR.ToLower().Contains(FilterActi.ToLower())) return true;
                        else return false;
                    }
    
                };
    
            }
    
            ICollectionView actiCollView;
            ObservableCollection<Activite> actiColl = new ObservableCollection<Activite>();
            public ObservableCollection<Activite> ActiColl
            {
                get { return actiColl; }
                set { actiColl = value; RaisePropertyChanged("ActiColl"); }
            }
    
            String filterActi;
            public String FilterActi
            {
                get { return filterActi; }
                set
                {
                    if (value != filterActi)
                    {
                        filterActi = value;
                        flag = true;
                        actiCollView.Refresh();
                        flag = false;
                        RaisePropertyChanged("FilterActi");
                    }
                }
            }
    
            Activite selectedActi;
            public Activite SelectedActi
            {
                get { return selectedActi; }
                set
                {
                    if (flag == false)
                    {
                        //Ce test est effectué voir si une activité n'a pas été supprimé
                        if (value == null) selectedActi = null;
                        else
                        {
                            if (ActiColl.Where(x => x.NIdActivite == value.NIdActivite).FirstOrDefault() != null)
                                selectedActi = ActiColl.Where(x => x.NIdActivite == value.NIdActivite).FirstOrDefault();
                            else
                            {
                                if (SelectedEntCopy.SType == "G") selectedActi = new ActiGarage();
                                else selectedActi = new ActiClient();
                            }
    
                        }
    
                        if (SelectedEntCopy.SType == "G")
                        {
                            SelectedActiCopy = new ActiGarage(value);
                            SelectedEntCopy.Acti = new ActiGarage(value);
                        }
                        else
                        {
                            SelectedActiCopy = new ActiClient(value);
                            SelectedEntCopy.Acti = new ActiClient(value);
                        }
    
                        RaisePropertyChanged("SelectedActi");
                    }
                }
            }
    
            bool flag = false;
            private String type;
    
            Entite selectedEntCopy;
            public Entite SelectedEntCopy
            {
                get { return selectedEntCopy; }
                set
                {
                    selectedEntCopy = value;
    
                    if (type != selectedEntCopy.SType)
                    {
                        Activite[] lstActi = null;
                        actiColl.Clear();
    
                        if (selectedEntCopy.SType == "G") lstActi = (facto.getIActivite()).ListActiGarage();
                        else lstActi = (facto.getIActivite()).ListActiClient();
    
                        if (lstActi != null)
                            foreach (Activite acti in lstActi)
                                this.actiColl.Add(acti);
                        type = selectedEntCopy.SType;
                    }
    
                    SelectedActi = selectedEntCopy.Acti;
                    RaisePropertyChanged("SelectedEntCopy");
    
                }
            }
            
            Activite selectedActiCopy;
            public Activite SelectedActiCopy
            {
                get { return selectedActiCopy; }
                set { selectedActiCopy = value; RaisePropertyChanged("SelectedActiCopy"); }
            }
    
            private bool isAddActiviteMod;
            public bool IsAddActiviteMod
            {
                get { return isAddActiviteMod; }
                set { isAddActiviteMod = value; }
            }
    
            public ICommand SaveActivite { get { return new RelayCommand(SaveExecute, CanSaveExecute); } }
            bool CanSaveExecute() { return true; }
            void SaveExecute()
            {
                int id;
                if (IsAddActiviteMod == true)
                {
                    ActiColl.Add(selectedActiCopy);
                    SelectedActi = ActiColl[ActiColl.Count - 1];
    
                    SelectedActi.NIdActivite = (facto.getIActivite()).InsertActivite(SelectedActi);
                }
                else
                {
                    id = actiColl.IndexOf(SelectedActi);
    
                    if (SelectedEntCopy.SType == "G") ActiColl[id] = new ActiGarage(SelectedActiCopy);
                    else ActiColl[id] = new ActiClient(SelectedActiCopy); 
    
                    SelectedActi = actiColl[id];
                    
                    (facto.getIActivite()).UpdateActivite(SelectedActi);
    
                }
                IsAddActiviteMod = false;
            }
            public ICommand AddActivite { get { return new RelayCommand(AddExecute, CanAddExecute); } }
            bool CanAddExecute() { return true; }
            void AddExecute()
            {
                IsAddActiviteMod = true;
                if (SelectedEntCopy.SType == "G") SelectedActiCopy = new ActiGarage();
                else SelectedActiCopy = new ActiClient();
            }
    
            public ICommand RemoveActivite { get { return new RelayCommand(RemoveActiviteExecute, CanRemoveActiviteExecute); } }
            bool CanRemoveActiviteExecute() { return true; }
            void RemoveActiviteExecute()
            {
                
                    flag = true;
                    actiColl.Remove(SelectedActi);
                    (facto.getIActivite()).DeleteActivite(selectedActi);
                    if (SelectedEntCopy.SType == "G") selectedActi = new ActiGarage();
                    else selectedActi = new ActiClient();
    
                    RaisePropertyChanged("SelectedActi");
                    flag = false;
                
            }
            
        }
    }

    Pour ce UserControl, je me suis servi des références :

    Kent.Boogaart.Windows.Controls

    GalaSoft.MvvmLight.WPF4

    En espérant que ca puisse aider quelqu'un :-)

    • Marqué comme réponse Aurel Bera lundi 1 juillet 2013 08:18
    lundi 1 juillet 2013 08:09