简体   繁体   English

在Windows 8中使用c#设置菜单弹出窗口背景颜色

[英]Set Menu Flyout background color using c# in windows 8

I want to set menu flyout background with c# because I am creating flyout at runtime how can I do that I know this with xaml like this 我想用c#设置菜单弹出窗口背景,因为我在运行时创建弹出窗口我该怎么做呢我用xaml这样知道这个

<Flyout.FlyoutPresenterStyle>
            <Style TargetType="FlyoutPresenter">
                <Setter Property="ScrollViewer.ZoomMode" Value="Enabled"/>
                <Setter Property="Background" Value="Black"/>
                <Setter Property="BorderBrush" Value="Gray"/>
                <Setter Property="BorderThickness" Value="5"/>
                <Setter Property="MinHeight" Value="300"/>
                <Setter Property="MinWidth" Value="300"/>
            </Style>
        </Flyout.FlyoutPresenterStyle>

How to achieve this using c#? 如何使用c#实现这一目标?

Finally solved it 终于解决了

  MenuFlyout m = new MenuFlyout();
  Style s = new Windows.UI.Xaml.Style { TargetType = typeof(MenuFlyoutPresenter) };
  s.Setters.Add(new Setter(BackgroundProperty,new SolidColorBrush(Colors.Blue)));
  MenuFlyoutItem mn = new MenuFlyoutItem();
  m.MenuFlyoutPresenterStyle = s;
  m.Items.Add(mn);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM