如何在Windows 10 UWP中从c#设置MenuFlyout的高度?

时间:2015-11-10 11:56:03

标签: c# xaml windows-runtime uwp

我在c#中有一个var initQuantitiesDropdown = function () { var options = []; var selectedFruit = $("#fruits").val(); $.each(pageData.products[selectedFruit].quantities, function (key, value) { options.push({ text: value, id: key }); }) $("#quantities").empty().select2({ data: options }); }; $("#fruits").select2().change(initQuantitiesDropdown); initQuantitiesDropdown(); ,我想设置此弹出窗口的高度,我怎么能这样做,因为它不包含高度属性。

1 个答案:

答案 0 :(得分:3)

请在C#代码中尝试:

private void menuFlyout_Opened(object sender, object e)
{         
    MenuFlyout m = sender as MenuFlyout;
    Style s = new Windows.UI.Xaml.Style { TargetType = typeof(MenuFlyoutPresenter) };
    s.Setters.Add(new Setter(MinHeightProperty, "800"));
    m.MenuFlyoutPresenterStyle = s;
}

这将获得与以下XAML代码相同的效果:

 <MenuFlyout Opened="menuFlyout_Opened">
       <MenuFlyout.MenuFlyoutPresenterStyle>
           <Style TargetType="MenuFlyoutPresenter">
              <Setter Property="MinHeight" Value="800" />
           </Style>
        </MenuFlyout.MenuFlyoutPresenterStyle>
  </MenuFlyout>