Skip to content

Commit 9485af2

Browse files
committed
More Fluid Window Resize
1 parent 9b0200a commit 9485af2

File tree

4 files changed

+70
-34
lines changed

4 files changed

+70
-34
lines changed

Files/UserControls/Ribbon/RibbonArea.xaml.cs

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -29,36 +29,6 @@ public RibbonArea()
2929

3030
private void Current_SizeChanged(object sender, Windows.UI.Core.WindowSizeChangedEventArgs e)
3131
{
32-
33-
34-
35-
// Ignore selected File Menu (index 0)
36-
if (RibbonTabView.SelectedIndex > 0 && RibbonTabView.IsLoaded)
37-
{
38-
double totalWidth = 0;
39-
var allItems = ((RibbonTabView.Items[RibbonTabView.SelectedIndex] as TabViewItem).Content as RibbonPage).PageContent;
40-
var RibbonItems = allItems.Where(x => x.DisplayMode != RibbonItemDisplayMode.Divider);
41-
foreach(IRibbonItem item in RibbonItems)
42-
{
43-
totalWidth += item.EstimatedWidth;
44-
}
45-
double averageItemWidth = 145;
46-
int visibleItemCapacity = int.Parse(Math.Round(Window.Current.Bounds.Width / averageItemWidth).ToString());
47-
int totalRibbonCommandItemsCount = RibbonItems.Count();
48-
var itemsToShow = RibbonItems.Take(visibleItemCapacity);
49-
var itemsToMakeCompact = RibbonItems.TakeLast(totalRibbonCommandItemsCount - itemsToShow.Count());
50-
foreach (RibbonCommandItem item in itemsToShow)
51-
{
52-
item.DisplayMode = RibbonItemDisplayMode.Tall; // TODO: Implement Tall Ribbon Items AppSetting
53-
}
54-
55-
foreach (RibbonCommandItem itemToCollapse in itemsToMakeCompact)
56-
{
57-
itemToCollapse.DisplayMode = RibbonItemDisplayMode.Compact;
58-
}
59-
}
60-
61-
6232
if (Window.Current.Bounds.Width >= 800)
6333
{
6434
if (App.CurrentInstance != null)
@@ -73,6 +43,45 @@ private void Current_SizeChanged(object sender, Windows.UI.Core.WindowSizeChange
7343

7444
RibbonViewModel.HideAppBarSeparator();
7545
}
46+
47+
// Ignore selected File Menu (index 0)
48+
if (RibbonTabView.SelectedIndex > 0 && RibbonTabView.IsLoaded)
49+
{
50+
var freeSpaceWidth = ((RibbonTabView.Items[RibbonTabView.SelectedIndex] as TabViewItem).Content as RibbonPage).FreeSpaceGrid.ActualWidth;
51+
if (freeSpaceWidth <= 10)
52+
{
53+
var allItems = ((RibbonTabView.Items[RibbonTabView.SelectedIndex] as TabViewItem).Content as RibbonPage).PageContent;
54+
var RibbonItems = allItems.Where(x => x.DisplayMode != RibbonItemDisplayMode.Divider && x.DisplayMode != RibbonItemDisplayMode.Compact);
55+
if(RibbonItems.Count() > 0)
56+
{
57+
var itemToMakeCompact = RibbonItems.Last();
58+
itemToMakeCompact.DisplayMode = RibbonItemDisplayMode.Compact;
59+
freeSpaceWidth = ((RibbonTabView.Items[RibbonTabView.SelectedIndex] as TabViewItem).Content as RibbonPage).FreeSpaceGrid.ActualWidth;
60+
}
61+
else
62+
{
63+
return;
64+
}
65+
66+
}
67+
68+
if (freeSpaceWidth >= 125)
69+
{
70+
var allItems = ((RibbonTabView.Items[RibbonTabView.SelectedIndex] as TabViewItem).Content as RibbonPage).PageContent;
71+
var RibbonItems = allItems.Where(x => x.DisplayMode != RibbonItemDisplayMode.Divider && x.DisplayMode == RibbonItemDisplayMode.Compact);
72+
if(RibbonItems.Count() > 0)
73+
{
74+
var itemToMakeFullSize = RibbonItems.First();
75+
itemToMakeFullSize.DisplayMode = RibbonItemDisplayMode.Wide;
76+
freeSpaceWidth = ((RibbonTabView.Items[RibbonTabView.SelectedIndex] as TabViewItem).Content as RibbonPage).FreeSpaceGrid.ActualWidth;
77+
}
78+
else
79+
{
80+
return;
81+
}
82+
83+
}
84+
}
7685
}
7786

7887
private void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e)

Files/UserControls/Ribbon/RibbonCommandItem.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
CornerRadius="{TemplateBinding CornerRadius}">
3535
<Grid
3636
x:Name="ContentRoot"
37-
MinHeight="{ThemeResource AppBarThemeMinHeight}"
37+
MinHeight="40"
3838
Margin="-1,0">
3939

4040
<Grid.ColumnDefinitions>
@@ -139,9 +139,9 @@
139139
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="TextLabel" Storyboard.TargetProperty="Visibility">
140140
<DiscreteObjectKeyFrame KeyTime="0" Value="Collapsed" />
141141
</ObjectAnimationUsingKeyFrames>
142-
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentViewbox" Storyboard.TargetProperty="Margin">
142+
<!--<ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentViewbox" Storyboard.TargetProperty="Margin">
143143
<DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource AppBarButtonContentViewboxCompactMargin}" />
144-
</ObjectAnimationUsingKeyFrames>
144+
</ObjectAnimationUsingKeyFrames>-->
145145
</Storyboard>
146146
</VisualState>
147147
<VisualState x:Name="LabelOnRight">

Files/UserControls/Ribbon/RibbonCommandItem.xaml.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,26 @@ public sealed partial class RibbonCommandItem : UserControl, IRibbonItem
2727
public RibbonCommandItem()
2828
{
2929
this.InitializeComponent();
30+
this.Loaded += RibbonCommandItem_Loaded;
31+
}
32+
33+
private void RibbonCommandItem_Loaded(object sender, RoutedEventArgs e)
34+
{
35+
switch (ItemDisplayMode)
36+
{
37+
case RibbonItemDisplayMode.Wide:
38+
VisualStateManager.GoToState(rootAppBarButton, "LabelOnRight", true);
39+
break;
40+
case RibbonItemDisplayMode.Tall:
41+
VisualStateManager.GoToState(rootAppBarButton, "FullSize", true);
42+
break;
43+
case RibbonItemDisplayMode.Compact:
44+
VisualStateManager.GoToState(rootAppBarButton, "Compact", true);
45+
break;
46+
case RibbonItemDisplayMode.Divider:
47+
throw new NotSupportedException();
48+
break;
49+
}
3050
}
3151

3252
public IconElement Icon { get; set; }

Files/UserControls/Ribbon/RibbonPage.xaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,12 @@
8686
</Style>
8787
</UserControl.Resources>
8888

89-
<StackPanel x:Name="PageContentPanel" Orientation="Horizontal" />
89+
<Grid>
90+
<Grid.ColumnDefinitions>
91+
<ColumnDefinition Width="Auto"/>
92+
<ColumnDefinition Width="*"/>
93+
</Grid.ColumnDefinitions>
94+
<StackPanel Grid.Column="0" x:Name="PageContentPanel" Orientation="Horizontal" />
95+
<Grid x:Name="FreeSpaceGrid" x:FieldModifier="public" Grid.Column="1"/>
96+
</Grid>
9097
</UserControl>

0 commit comments

Comments
 (0)