locked
Get absolute position of an image control with mvvm

    Question

  • Hi, I have a question of getting the absolute position of an image control in view model by using MVVM?

    The XAML is as follow

    <Window x:Class="View.MainWindow"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
            Title="MainWindow" Height="600" Width="800">
        <Grid>
            <DockPanel HorizontalAlignment="Stretch" LastChildFill="True" VerticalAlignment="Stretch">
                <Label DockPanel.Dock="Bottom" Content="Label" Height="35" VerticalAlignment="Bottom" FontSize="20" Background="#FF020202" FontFamily="Microsoft Sans Serif" Foreground="#FFFBF8F8"/>
                <Grid DockPanel.Dock="Left" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" >
                    <Viewbox Stretch="Uniform">
                        <Image Name="image" Width="513" Height="424" />
                    </Viewbox>
                    <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ShowGridLines="True">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="1*"/>
                            <RowDefinition Height="3*"/>
                            <RowDefinition Height="1*"/>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="1*"/>
                            <ColumnDefinition Width="3*"/>
                            <ColumnDefinition Width="1*"/>
                        </Grid.ColumnDefinitions>
                        <Grid Grid.Column="1" Grid.Row="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ShowGridLines="True">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="1*"/>
                                <RowDefinition Height="1*"/>
                                <RowDefinition Height="1*"/>
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="1*"/>
                                <ColumnDefinition Width="2*"/>
                                <ColumnDefinition Width="1*"/>
                                <ColumnDefinition Width="2*"/>
                                <ColumnDefinition Width="1*"/>
                            </Grid.ColumnDefinitions>
                            <Viewbox Grid.Column="1" Grid.Row="1" Stretch="Uniform">
                                <Image VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Height="473" Width="476" Source="pack://siteoforigin:,,,/Resources/startButton.png">
                                    <i:Interaction.Triggers>
                                        <i:EventTrigger EventName="MouseEnter">
                                            <i:InvokeCommandAction Command="{Binding _startButtonMouseOverCommand}"/>
                                        </i:EventTrigger>
                                    </i:Interaction.Triggers>
                                </Image>
                            </Viewbox>
                            <Viewbox Grid.Column="3" Grid.Row="1" Stretch="Uniform">
                                <Image VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Height="473" Width="476" Source="pack://siteoforigin:,,,/Resources/StopButton.png"/>
                            </Viewbox>
                        </Grid>
                    </Grid>
                </Grid>
                <Grid DockPanel.Dock="Right" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="Black"/>
            </DockPanel>
        </Grid>
    </Window>
    
    Thank you.
    Saturday, September 20, 2014 8:21 AM

Answers

  • Hi, Saiyi.

    You can write behavior for image and when image loaded set to DependencyProperty image's position. And you must binding some property from ViewMode to this dependencyProperty in behavior.

    Regards, Nikita.

    Saturday, September 20, 2014 8:33 AM