简体   繁体   中英

Handle Resize for Icons in Panel , UWP?

How to resize the MenuBarContainer according to window Resize? I have Group1 class which extent ContentPresenter and has 4 views (View1,View2,View3,View4).while window Resize,I need to switch the views based on the width of the Group1(ContentPresenter),(ie, Which view is suitable for current window Size). Maximum View is View1 and then view2->view3->view4.

My Complete Source Link

Handle Resize for Icons in Panel, UWP?

You could listen current CoreWindow SizeChanged event and get the changed size, when you change current window, you could calculate current zoom value base on previous window size. And then resize your icon zoom value.

For example

public Icon3(SvgImageSource contentIconSource, string contenttext)
{
    this.InitializeComponent();
    ContentIcon.Source = contentIconSource;
    ContentBlock.Text = contenttext;
    Loaded += Icon3_Loaded;
}

private void Icon3_Loaded(object sender, RoutedEventArgs e)
{
    Window.Current.CoreWindow.SizeChanged += CoreWindow_SizeChanged;
}
private double previousWidth;
private void CoreWindow_SizeChanged(Windows.UI.Core.CoreWindow sender, Windows.UI.Core.WindowSizeChangedEventArgs args)
{
    var size = args.Size;

    var windowWidth = size.Width;
    if (previousWidth != 0)
    {
        var zoomValue = windowWidth / previousWidth;
        Root.Width = this.ActualWidth * zoomValue;
    }
    previousWidth = windowWidth;
}

Update

private void Group1_Loaded(object sender, RoutedEventArgs e)
{
    Window.Current.CoreWindow.SizeChanged += CoreWindow_SizeChanged;
}

private void CoreWindow_SizeChanged(Windows.UI.Core.CoreWindow sender, Windows.UI.Core.WindowSizeChangedEventArgs args)
{
    var size = args.Size;

    var windowWidth = size.Width;
    if (0 < windowWidth && windowWidth < 500)
    {
        View4();
    }
    if (500 < windowWidth && windowWidth < 720)
    {
        View3();
    }
    if (720 < windowWidth && windowWidth < 1200)
    {
        View2();
    }

    if (1200 < windowWidth)
    {
        View1();
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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