2014-12-30 4 views
3

내 Windows Store 앱에 ScrollViewer 세트가 있는데 두 번 탭 (즉, 전체 크기로 확장) 될 때 항상 조치가 필요합니다. 그들은 다른 파일에있는, 또는 내가 아마 해당 파일에 대해 숨김 코드에 넣고 것 :Windows 런타임 애플리케이션의 동작

private void ScrollViewer_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e) 
{ 
    ScrollViewer sv = (ScrollViewer)sender; 
    if (sv.HorizontalScrollBarVisibility == ScrollBarVisibility.Disabled) 
    { 
     sv.HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden; 
    } 
    else 
    { 
     sv.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled; 
    } 
} 

내가 행동으로보고 들었다, 그래서 나는 행동을 연구하고의 도움으로 몇 온라인 자습서, 나는이 가지고 올 수 있었다 : 이제

class ViewboxDoubleTap : DependencyObject, IBehavior 
{ 
    public interface IBehavior 
    { 
     DependencyObject AssociatedObject { get; } 
     void Attach(DependencyObject associatedObject); 
     void Detach(); 
    } 

    public void Attach(DependencyObject associatedObject) 
    { 
     if ((associatedObject != AssociatedObject) && !DesignMode.DesignModeEnabled) 
     { 
      if (AssociatedObject != null) 
       throw new InvalidOperationException("Cannot attach behavior multiple times."); 

      AssociatedObject = associatedObject; 
      var fe = AssociatedObject as FrameworkElement; 
      if (fe != null) 
      { 
       fe.AddHandler(UIElement.DoubleTappedEvent, new DoubleTappedEventHandler(ScrollViewer_DoubleTapped), true); 
      } 
     } 
    } 

    public void Detach() 
    { 
     var fe = AssociatedObject as FrameworkElement; 
     if (fe != null) 
     { 
      fe.RemoveHandler(UIElement.DoubleTappedEvent, new DoubleTappedEventHandler(ScrollViewer_DoubleTapped)); 
     } 

     AssociatedObject = null; 
    } 

    public DependencyObject AssociatedObject { get; private set; } 

    private void ScrollViewer_DoubleTapped(object sender, DoubleTappedRoutedEventArgs e) 
    { 
     ScrollViewer sv = (ScrollViewer)sender; 
     if (sv.HorizontalScrollBarVisibility == ScrollBarVisibility.Disabled) 
     { 
      sv.HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden; 
     } 
     else 
     { 
      sv.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled; 
     } 
    } 
} 

은 모든 것이 잘 컴파일,하지만 난이는 XAML에 부착 얻을 수 없습니다

XML 네임 스페이스 :

xmlns:i="using:Microsoft.Xaml.Interactivity" 
xmlns:core="using:Microsoft.Xaml.Interactions.Core" 
xmlns:local="using:MyApp.Folder" 
xmlns:global="using:MyApp" 

관련 코드 :

<ScrollViewer HorizontalAlignment="Left" VerticalScrollBarVisibility="Hidden" MaxZoomFactor="2" MinZoomFactor="1" MaxWidth="1067"> 

    <i:Interaction.Behaviors> 
     <core:EventTriggerBehavior EventName="DoubleTapped"> 
      <global:ViewboxDoubleTap /> 
     </core:EventTriggerBehavior> 
    </i:Interaction.Behaviors> 

    <Border BorderBrush="Black" BorderThickness="1"> 
     <Image Source="MyImage.png"/> 
    </Border> 
</ScrollViewer> 

나는이 페이지로 이동하려고 아무 일도 발생하지 않고, 내가 디버깅 할 때, 그것은 나에게이 오류 메시지가 제공합니다 또한

WinRT information: Cannot add instance of type 'LearnOneNote.ViewboxDoubleTap' to a collection of type 'Microsoft.Xaml.Interactivity.ActionCollection'. [Line: 25 Position: 30] 

을 , ViewboxDoubleTapnamespace MyApp에 없지만, <global:을 입력하면 그 자체가 위로 올라옵니다. 이것이 문제에 중요한지 나는 모른다.

도움이 될 것입니다. IAction을 확인하기 위해 팁을주게 된 후에

답변

2

이 (당신, franssu 감사합니다),이 함께했다 : 이것은 완벽하게 작동

[DefaultEvent(typeof(ScrollViewer),"DoubleTapped")] 
public class ScrollViewerDoubleTap : DependencyObject, IAction 
{ 
    public object Execute(object sender, object parameter) 
    { 
     ScrollViewer sv = (ScrollViewer)sender; 
     if (sv.HorizontalScrollBarVisibility == ScrollBarVisibility.Disabled) 
     { 
      sv.HorizontalScrollBarVisibility = ScrollBarVisibility.Hidden; 
     } 
     else 
     { 
      sv.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled; 
     } 
     return sender; 
    } 
} 

.

관련 문제