MVVM - Item Templates - BringToFront

Aug 18, 2011 at 10:54 PM

Has anyone tried using the behaviour with a MVVM model ?

In the example the BringToFront Method in the behaviours looks for a panel parent to rejig the z-order of the items that are added at design time.

Using an Itemscontrol  and itemtemplate things are not the same

In the example below, the images are placed in a grid in the item template.

The BringToFront method finds the grid as the parent and not the itemsControl or the grid in the items control, therefore the z-order does not place the selected item at the top of the Zindex.

We have hacked this to use a selected item to remove / re add the item to the control as a work around, but would like to raise this as an issue ??

<UserControl x:Class="MultiTouch.Behaviors.Silverlight4.Sample.MainPage"
    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:interactivity="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
    xmlns:behaviors="clr-namespace:MultiTouch.Behaviors.Silverlight4;assembly=MultiTouch.Behaviors.Silverlight4" xmlns:controls="clr-namespace:MultiTouch.Behaviors.Silverlight4.Sample.DataProxy" mc:Ignorable="d"
    x:Name="MainRoot"
    d:DesignHeight="300" d:DesignWidth="400">
    <UserControl.Resources>
        <controls:DataContextProxy x:Key="DataContextProxy" />
    </UserControl.Resources>
    <Grid>
        <Grid.Background>
            <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                <GradientStop Color="#282B0808" Offset="1" />
                <GradientStop Color="#EE9BB79B" Offset="0" />
            </LinearGradientBrush>
        </Grid.Background>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="150" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="34" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <ItemsControl  Grid.Row="1" ItemsSource="{Binding Path=Pictures,Mode=TwoWay, UpdateSourceTrigger=Default}" Grid.Column="1">
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <Grid>
                    </Grid>
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <Canvas>
                        <Grid Background="BlanchedAlmond">
                            <interactivity:Interaction.Behaviors>
                                <behaviors:MultiTouchBehavior
                                IsRotateEnabled="True"
                                    CenterX="{Binding XPos}"
                                   
                                    CenterY="{Binding YPos}"
                                                    IsScaleEnabled="True"
                                                    IsTranslateEnabled="True"
                                                    IsPivotEnabled="True"
                                                    IsInertiaEnabled="True"
                                                    MinimumScale="20" MaximumScale="500" />
                            </interactivity:Interaction.Behaviors>

                            <Image Source="{Binding Path=BitMapImage}"  Stretch="UniformToFill">

                            </Image>
                            <Button Content="X" Height="30" Width="30" CommandParameter="{Binding}" Command="{Binding Source={StaticResource DataContextProxy}, Path=DataSource.DelChildItem}"  VerticalAlignment="Top" HorizontalAlignment="Right" Margin="0,1,1,0" Name="btn1"  FontSize="12" FontWeight="ExtraBold"/>
                        </Grid>
                    </Canvas>
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>

    </Grid>

</UserControl>

Aug 18, 2011 at 11:32 PM

Hi Bruce, thanks for the feedback.

Will open an issue and add this to the todo list.

Thanks!

Davide

Aug 18, 2011 at 11:32 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.