2012-04-19 105 views
1

我正在構建具有兩種視覺狀態的圖片查看器。視覺狀態處於活動狀態時動態縮放對象

A)申請的基本狀態(無的visualSTATE活性)

1) 「基」 態(的visualSTATE,空分鏡)

2) 「網格」 的所有圖像(的visualSTATE可以擴展圖像以季大小)

我想改變手勢之間的視覺狀態。捏目前的形象做到這一點。我還希望縮放手勢縮放圖像時捏(OnPinchDelta)。這隻適用於A)沒有視覺狀態激活。一旦我啓動視覺狀態1)或2)捏不再起作用。它仍然啓動visualstate更改,但不縮放圖像捏。

如何在視覺狀態處於活動狀態時修改圖像比例尺或如何退出任何活動的視覺狀態以使任何視覺狀態/故事板運行(I think the latter is impossible)?

捏的原因不再縮放圖像,而捏是因爲它以某種方式與視覺狀態衝突。在應用程序啓動時一切正常,但一旦視覺狀態被激活,它就不再有效。如果在應用程序啓動時,我將visualstate設置爲1)即使一次也不起作用。

編輯:我建立了一個簡化的例子。下面是相關的XAML(其餘的複製粘貼沒有工作,但否則它只是與工具包參考默認的WP頁面模板):

<!--LayoutRoot is the root grid where all page content is placed--> 
<Grid x:Name="LayoutRoot" Background="Transparent"> 
    <VisualStateManager.VisualStateGroups> 
     <VisualStateGroup x:Name="VisualStateGroup"> 
      <VisualState x:Name="Normal"/> 
      <VisualState x:Name="Grid"> 
       <Storyboard> 
        <DoubleAnimation Duration="0" To="0.3" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.ScaleX)" Storyboard.TargetName="image" d:IsOptimized="True"/> 
        <DoubleAnimation Duration="0" To="0.3" Storyboard.TargetProperty="(UIElement.RenderTransform).(CompositeTransform.ScaleY)" Storyboard.TargetName="image" d:IsOptimized="True"/> 
       </Storyboard> 
      </VisualState> 
     </VisualStateGroup> 
    </VisualStateManager.VisualStateGroups> 

    <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"/> 
    <Image x:Name="image" Source="cheetah-picture.jpg" Stretch="Uniform" VerticalAlignment="Top"> 
     <Image.RenderTransform> 
      <CompositeTransform x:Name="ImageTransformation"/> 
     </Image.RenderTransform> 
     <toolkit:GestureService.GestureListener> 
      <toolkit:GestureListener PinchDelta="OnPinchDelta" PinchCompleted="OnPinchCompleted" /> 
     </toolkit:GestureService.GestureListener> 
    </Image> 
</Grid> 

這裏的.CS

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Net; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Documents; 
using System.Windows.Input; 
using System.Windows.Media; 
using System.Windows.Media.Animation; 
using System.Windows.Shapes; 
using Microsoft.Phone.Controls; 

namespace Pincher 
{ 
public partial class MainPage : PhoneApplicationPage 
{ 
    public MainPage() 
    { 
     InitializeComponent(); 
    } 

    private void OnPinchDelta(object sender, PinchGestureEventArgs e) 
    { 
     ImageTransformation.ScaleX = 1 * e.DistanceRatio; 
     ImageTransformation.ScaleY = ImageTransformation.ScaleX; 
    } 

    private void OnPinchCompleted(object sender, PinchGestureEventArgs e) 
    { 

     bool squeezing = (e.DistanceRatio < 1) ? true : false; 

     if (squeezing == true) 
     { 
      VisualStateManager.GoToState(this, "Grid", true); 
      MessageBox.Show("grid"); 
     } 
     else 
     { 
      VisualStateManager.GoToState(this, "Normal", true); 
      MessageBox.Show("normal"); 
     } 
    } 
} 

}

結束。改變視覺狀態適用於捏。實際上,縮放圖片時,只有在沒有視覺狀態處於活動狀態時纔會進行收縮。如何在視覺狀態處於活動狀態時縮放項目?

回答

0

我認爲你遇到的問題是由於嘗試去基地狀態。 基地狀態是初始化控制時使用的默認狀態,但是一旦VSM(視覺狀態管理器)轉到不同的狀態,您不再處於基地狀態並且不能回到它。

在你的情況下,你應該有類似grid state和正常。並在這兩個狀態之間切換。

此外,如果你會去像在WP7狀態的默認按鈕樣式,你會發現,它具有普通MousOver在默認過渡組殘疾人狀態。並且當用戶沒有對按鈕做任何事情(並且它沒有被禁用)時,它會到正常狀態,不到BASE

+0

我明顯有實際的基態(無VSM)。然後是1)GRID狀態和2)「BASE」狀態。如果你想,你可以調用後者2)「NORMAL」,但這只是關於名稱的語義。該狀態是空的。問題是,只要我運行任何視覺狀態,我就不能再縮放受狀態影響的圖像。在視覺狀態正在運行時,圖像根本不會縮放,並且由於您無法退出視覺狀態,因此我無法再對其進行縮放,除非您以某種方式針對特定視覺狀態下的對象縮放比例 - 這是可能的嗎? – Hardev 2012-04-23 08:01:11

+0

您可以發佈您的XAML(特別是VSM位)。 – Vitalij 2012-04-23 19:56:32

+0

我編輯了我原來的帖子。它現在包含一個簡化的例子。出於某種原因,我無法複製粘貼完整的XAML,但不包含的僅僅是默認的WP頁面模板。 – Hardev 2012-04-25 07:00:22

相關問題