2010-01-22 1 views
1

내 ChildWindow 서브 클래스와 함께 VisualStateManager를 사용할 수있는 방법이 있습니까? VisualStateManager에 대한 호출은 아무 것도하지 않으며,이를 수행하는 유일한 방법은 스토리 보드를 수동으로 호출하는 것입니다. 너무나 가볍고 실수하기 쉽습니다. 누구든지 그것을 성취 할 방법을 찾았습니까?ChildWindow에서 VisualStates를 사용하려면 어떻게해야합니까?

예제 코드으로 업데이트되었습니다. 이를 사용하려면 새 Silverlight 프로젝트를 만들고 기본 페이지에서 단추를 클릭하여 ExampleWindow.ShowWindow()를 호출하면됩니다. 생성자가 버튼을 숨겨야하는 상태를 설정하더라도 버튼을 볼 수 있습니다.

XAML (ExampleWindow.xaml) :

<controls:ChildWindow 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d" 
    xmlns:ic="clr-namespace:Microsoft.Expression.Interactivity.Core;assembly=Microsoft.Expression.Interactions" 
    x:Class="Client.Windows.ExampleWindow" 
    Title="Example"> 
    <Grid x:Name="LayoutRoot"> 
     <VisualStateManager.VisualStateGroups> 
      <VisualStateGroup x:Name="ExampleStateGroup"> 
       <VisualState x:Name="ExampleBaseState"> 
        <Storyboard> 
         <DoubleAnimationUsingKeyFrames BeginTime="00:00:00" Duration="00:00:00.0010000" Storyboard.TargetName="button" Storyboard.TargetProperty="(UIElement.Opacity)"> 
          <EasingDoubleKeyFrame KeyTime="00:00:00" Value="0"/> 
         </DoubleAnimationUsingKeyFrames> 
        </Storyboard> 
       </VisualState> 
      </VisualStateGroup> 
     </VisualStateManager.VisualStateGroups> 
     <VisualStateManager.CustomVisualStateManager> 
      <ic:ExtendedVisualStateManager/> 
     </VisualStateManager.CustomVisualStateManager> 
     <Button x:Name="button" Content="You Shouldn't See Me" Grid.ColumnSpan="2" Width="150" Height="150" HorizontalAlignment="Center" VerticalAlignment="Center"/> 
    </Grid> 
</controls:ChildWindow> 

코드 뒤에 (ExampleWindow.xaml.cs) :

using System.Windows; 
using System.Windows.Controls; 

namespace Client.Windows 
{ 
    public partial class ExampleWindow : ChildWindow 
    { 
     public ExampleWindow() 
     { 
      InitializeComponent(); 

      VisualStateManager.GoToState(this, "ExampleBaseState", true); 
     } 

     public static void ShowWindow() 
     { 
      var w = new ExampleWindow(); 
      w.Show(); 
     } 
    } 
} 
+0

ChildWindow가 VisualStateManager를 사용할 수없는 이유를 생각할 수 없습니다. 코드의 일부를 보여 주어야합니까? – AnthonyWJones

+0

ChildWindow의 템플릿에 Open 및 Closed VisualStates가있어서 VisualStateGroups에 대한 VisualTree 검색이 멈추고 컨트롤의 상태가 지속되지 않는다고 생각합니다. (디자인 타임에 Blend에서 제대로 작동하지만). – Dov

답변

0

지금까지 내가 발견 한 유일한 해결 방법은 아무것도 넣어하는 것입니다 UserControl에 시각적 상태가 필요합니다. UserControl은 상태를 가질 수 있으며 성공적으로 상태를 전환 할 수 있으며 이벤트, 메서드 및 속성을 통해 ChildWindow에 필요한 모든 것을 전달할 수 있습니다.

0

ChildWindows에서 Dov로 작동하지 않는 VSM과 동일한 문제가 발생했습니다. 내가 한 것은 내 ChildWindow를 UserControl로 변경 한 다음 UserControl을 일반 ChildWindow의 내용으로 설정 한 다음 여는 것입니다.

var childWindow = new ChildWindow { Content = someUserControl }; 

이제 문제는 코드-behing가있는 UserControl에있을 것입니다 때문에 당신이 ChildWindow 클래스의 DialogResult를 기능을 잃게됩니다. ChildWindow의 DialogResult 속성에 액세스하는 가장 간단한 방법은 UserControl 내에서 Parent 속성을 사용하는 것입니다.

+0

그 일은 내가 거의 끝내는 것처럼 들린다. – Dov

0

ChildWindow 템플릿은 일반적인 자식 창 애니메이션에 대한 VisualStateGroup "CommonStates"을 관리하는 VisualStateManager가 포함되어 있습니다. VisualStateManager.GoToState를 호출하면 ChildWindow Template CommonStates VisualStateGroup에서 상태를 찾습니다. 따라서 ChildWindow에서 만든 ExtendedVisualStateManager 및 VisualStateGroup "ExampleStateGroup"에 액세스해야합니다. 해킹하는 방법 중 하나 인이 작업을 수행 한 유일한 방법은 상태 변경을 위해 호출되는 고유 한 GoToState 함수를 만드는 것입니다.

public ExampleWindow() 
{ 
    InitializeComponent(); 

    MyGoToState("ExampleBaseState"); 
} 

public void MyGoToState(string stateIn) 
{ 

    VisualState stateShow = null; 

    VisualStateGroup ExampleStateGroup as VisualStateGroup 

    if(ExampleStateGroup != null) 
    { 
     for(int i= 0; i < ExampleStateGroup.States.Count; i++) 
     { 
      stateShow = ExampleStateGroup.States[i] as VisualState; 

      if(stateShow != null) 
      { 

       if(stateShow.Name == stateIn.Trim()) 
       { 
        stateShow.Storyboard.Begin(); 
       } 

      } 

     } 
    } 
}