2015-10-05 59 views
0

我需要的项目在ToogleMenuFlyout占据屏幕的完整width。 但我没有解决问题。ToogleMenuFlyout和MenuFlyoutPresenterStyle设置宽度 - Windows 10 Mobile

我试图把我的网格(网格主页)的width,但我不会在代码隐藏。

我正在将样式应用于MenuFlyoutPresenterStyle但也不给。

我的代码是:

AppBarButton x:Name="FiltersPhone" Icon="Filter" Label="Names"> 
       <AppBarButton.Flyout> 
        <MenuFlyout> 
        <MenuFlyout.MenuFlyoutPresenterStyle> 
         <Style TargetType="MenuFlyoutPresenter"> 
          <Setter Property="Background" Value="Transparent"/> 
          <Setter Property="BorderThickness" Value="0"/> 
          <Setter Property="Margin" Value="0,4,0,0"/> 
         </Style> 
        </MenuFlyout.MenuFlyoutPresenterStyle> 
        <ToggleMenuFlyoutItem x:Name="FlyoutItemDate" Text="Today" Tag="Date" 
              IsChecked="True/> 

       </MenuFlyout> 
       </AppBarButton.Flyout> 
      </AppBarButton> 

回答

1

应用下应有助于[更新,可支持横向]:

需要注意的是:这仍然不是一个完美的解决方案,以满足您的所有需求。我只是想让你了解MenuFlyoutPresenter的最大宽度,ToggleMenuFlyoutItem的宽度属性是推动你想要的关键。

  1. 集X:NAME = “rootGrid” 页面的根格

  2. 在后台代码,实现以下功能MenuFlyoutPresenter的

    public Page2() 
    { 
        this.InitializeComponent(); 
        this.Loaded += Page2_Loaded; 
    } 
    
    private void Page2_Loaded(object sender, RoutedEventArgs e) 
    { 
        FlyoutItemDate.Width = rootGrid.ActualWidth; 
        DisplayInformation di = DisplayInformation.GetForCurrentView(); 
        di.OrientationChanged += Di_OrientationChanged; 
    } 
    
    private void Di_OrientationChanged(DisplayInformation sender, object args) 
    { 
        if (sender.CurrentOrientation == DisplayOrientations.Portrait) 
        { 
         FlyoutItemDate.Width = rootGrid.ActualWidth; 
        } 
        else if(sender.CurrentOrientation == DisplayOrientations.Landscape) 
        { 
         FlyoutItemDate.Width = rootGrid.ActualHeight; 
        } 
    } 
    
  3. 增加maxwidth较大的一个(如1000)

    <Style TargetType="MenuFlyoutPresenter"> 
         <Setter Property="Background" Value="Red"/> 
         <Setter Property="BorderThickness" Value="0"/> 
         <Setter Property="Margin" Value="0,4,0,0"/> 
         <Setter Property="MaxWidth" Value="1000"/> 
    </Style> 
    

这里是结果,我把背景变成红色来说清楚: enter image description here

+0

嗨,谢谢,但不适用于横向模式。只有肖像是好的。 我不知道我做了什么更多:( – fipcurren88

+0

更新了我的答案。在横向模式下,将网格的高度设置为项目的宽度,并将MenuFlyoutPresenter的Maxwidth属性设置为较大值。 –

+0

嗨,模式中肖像是完美的! 但是在风景模式没有占用屏幕宽度奇怪:( – fipcurren88