2016-02-17 81 views
0

例如,當您爲按鈕控件添加彈出工具時,點擊該按鈕後,彈出窗口將顯示一個依賴於彈出窗口的「放置」屬性的過渡動畫。如果「展示位置」設置爲「頂部」,則動畫看起來像從該按鈕下拉菜單。在我的情況下,我想要完全刪除動畫,或者使它從該按鈕的x和y擴展。怎麼做?是否可以刪除或更改默認彈出過渡動畫?

回答

2

也有類似的情況:How to change ContentDialog transition

正如Rob Caplan所說,你不能重寫ContentDialog中的轉換等。它們被設計成簡單的方法來獲得標準行爲,並且總是使用PopupThemeTransition。

所以,如果你想要非標準的行爲,那麼你可以寫一個自定義控件,它使用你自己的TransitionCollection或沒有Transition

例如:

<UserControl 
    x:Class="Is_it_possible_to_remove_or_change_default_flyou.MyUserControl1" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="using:Is_it_possible_to_remove_or_change_default_flyou" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d" 
    d:DesignHeight="300" 
    d:DesignWidth="400" 
    LostFocus="UserControl_LostFocus"> 

    <UserControl.Transitions> 
     <TransitionCollection> 
      <!--Add the Transition that you want--> 
     </TransitionCollection> 
    </UserControl.Transitions> 

    <Grid Name="MyGrid" BorderBrush="Gray" BorderThickness="1" Background="LightGray"> 
     <StackPanel> 
      <TextBox Name="MyText" Text="Hello"></TextBox> 
      <TextBox Text="!"></TextBox> 
     </StackPanel> 
    </Grid> 
</UserControl> 

背後的代碼:

public sealed partial class MyUserControl1 : UserControl 
{ 
    public Popup hostPopup; 
    public double actHei; 
    public double actWei; 

    public MyUserControl1() 
    { 
     this.InitializeComponent(); 
     hostPopup = new Popup(); 
     hostPopup.Child = this; 
    } 

    public void Show() 
    { 
     hostPopup.IsOpen = true; 
     actHei = MyGrid.ActualHeight; 
     actWei = MyGrid.ActualWidth; 
     MyText.Focus(FocusState.Pointer); 
    } 

    private void UserControl_LostFocus(object sender, RoutedEventArgs e) 
    { 
     hostPopup.IsOpen = false; 
    } 
} 

在後面的MainPage代碼:

public sealed partial class MainPage : Page 
{ 
    public MyUserControl1 popup; 

    public MainPage() 
    { 
     this.InitializeComponent(); 
     popup = new MyUserControl1(); 
    } 

    private void Button_Click(object sender, RoutedEventArgs e) 
    { 
     if (popup.hostPopup.IsOpen != true) 
     { 
      var ttv = MyButton.TransformToVisual(Window.Current.Content); 
      Point screenCoords = ttv.TransformPoint(new Point(0, 0)); 
      popup.hostPopup.VerticalOffset = screenCoords.Y - 100; 
      popup.hostPopup.HorizontalOffset = screenCoords.X; 
      popup.Show(); 
     } 
    } 
} 
相關問題