Permalink
Browse files

fix toggling UseNoneWindowStyle

  • Loading branch information...
punker76 committed Jan 31, 2015
1 parent 0b4c787 commit c1d36f5eb4b22cea92383c256f4c1102141696ce
@@ -361,10 +361,26 @@ private static void OnUseNoneWindowStylePropertyChangedCallback(DependencyObject
if (e.NewValue != e.OldValue)
{
// if UseNoneWindowStyle = true no title bar should be shown
if ((bool)e.NewValue)
{
((MetroWindow)d).ShowTitleBar = false;
}
var useNoneWindowStyle = (bool)e.NewValue;
var window = (MetroWindow)d;
window.ToggleNoneWindowStyle(useNoneWindowStyle);
}
}
private void ToggleNoneWindowStyle(bool useNoneWindowStyle)
{
// UseNoneWindowStyle means no title bar, window commands or min, max, close buttons
if (useNoneWindowStyle)
{
ShowTitleBar = false;
}
if (LeftWindowCommandsPresenter != null)
{
LeftWindowCommandsPresenter.Visibility = useNoneWindowStyle ? Visibility.Collapsed : Visibility.Visible;
}
if (RightWindowCommandsPresenter != null)
{
RightWindowCommandsPresenter.Visibility = useNoneWindowStyle ? Visibility.Collapsed : Visibility.Visible;
}
}
@@ -664,21 +680,7 @@ private void MetroWindow_Loaded(object sender, RoutedEventArgs e)
VisualStateManager.GoToState(this, "AfterLoaded", true);
}
// if UseNoneWindowStyle = true no title bar, window commands or min, max, close buttons should be shown
if (UseNoneWindowStyle)
{
if (LeftWindowCommandsPresenter != null)
{
LeftWindowCommandsPresenter.Visibility = Visibility.Collapsed;
}
if (RightWindowCommandsPresenter != null)
{
RightWindowCommandsPresenter.Visibility = Visibility.Collapsed;
}
ShowMinButton = false;
ShowMaxRestoreButton = false;
ShowCloseButton = false;
}
this.ToggleNoneWindowStyle(this.UseNoneWindowStyle);
if (this.Flyouts == null)
{
@@ -27,25 +27,44 @@ public static ResizeModeMinMaxButtonVisibilityConverter Instance
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values != null && values.Length == 2 && parameter is string)
var whichButton = parameter as string;
if (values != null && !string.IsNullOrEmpty(whichButton))
{
var windowPropValue = (bool)values[0];
var windowResizeMode = (ResizeMode)values[1];
var whichButton = (string)parameter;
var showButton = values.Length > 0 && (bool) values[0];
var useNoneWindowStyle = values.Length > 1 && (bool)values[1];
var windowResizeMode = values.Length > 2 ? (ResizeMode)values[2] : ResizeMode.CanResize;
if (whichButton == "CLOSE")
{
if (useNoneWindowStyle)
{
return Visibility.Collapsed;
}
return showButton ? Visibility.Visible : Visibility.Collapsed;
}
switch (windowResizeMode)
{
case ResizeMode.NoResize:
return Visibility.Collapsed;
case ResizeMode.CanMinimize:
if (whichButton == "MIN")
{
return windowPropValue ? Visibility.Visible : Visibility.Collapsed;
if (useNoneWindowStyle)
{
return Visibility.Collapsed;
}
return showButton ? Visibility.Visible : Visibility.Collapsed;
}
return Visibility.Collapsed;
case ResizeMode.CanResize:
case ResizeMode.CanResizeWithGrip:
default:
return windowPropValue ? Visibility.Visible : Visibility.Collapsed;
if (useNoneWindowStyle)
{
return Visibility.Collapsed;
}
return showButton ? Visibility.Visible : Visibility.Collapsed;
}
}
return Visibility.Visible;
@@ -513,6 +513,9 @@
<Binding Path="ShowMinButton"
RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type Controls:MetroWindow}}"
Mode="OneWay" />
<Binding Path="UseNoneWindowStyle"
RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type Controls:MetroWindow}}"
Mode="OneWay" />
<Binding Path="ResizeMode"
RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type Controls:MetroWindow}}"
Mode="OneWay" />
@@ -534,6 +537,9 @@
<Binding Path="ShowMaxRestoreButton"
RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type Controls:MetroWindow}}"
Mode="OneWay" />
<Binding Path="UseNoneWindowStyle"
RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type Controls:MetroWindow}}"
Mode="OneWay" />
<Binding Path="ResizeMode"
RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type Controls:MetroWindow}}"
Mode="OneWay" />
@@ -553,8 +559,18 @@
RenderOptions.EdgeMode="Aliased"
Style="{Binding WindowCloseButtonStyle, Mode=OneWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Controls:MetroWindow}}}"
ToolTip="{Binding Close, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Controls:WindowButtonCommands}}}"
IsEnabled="{Binding IsCloseButtonEnabled, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Controls:MetroWindow}}}"
Visibility="{Binding ShowCloseButton, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Controls:MetroWindow}}, Converter={StaticResource BooleanToVisibilityConverter}}">
IsEnabled="{Binding IsCloseButtonEnabled, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Controls:MetroWindow}}}">
<Button.Visibility>
<MultiBinding Converter="{x:Static conv:ResizeModeMinMaxButtonVisibilityConverter.Instance}"
ConverterParameter="CLOSE">
<Binding Path="ShowCloseButton"
RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type Controls:MetroWindow}}"
Mode="OneWay" />
<Binding Path="UseNoneWindowStyle"
RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type Controls:MetroWindow}}"
Mode="OneWay" />
</MultiBinding>
</Button.Visibility>
<Path Data="M 10.009,1.704 L 8.331,0.026 5.03,3.327 1.703,0 0,1.704 3.326,5.031 0.025,8.332 1.703,10.009 5.004,6.708 8.305,10.009 10.009,8.305 6.708,5.005"
SnapsToDevicePixels="True"
Fill="{Binding Path=Foreground, RelativeSource={RelativeSource AncestorType=Button}}" />
@@ -164,7 +164,7 @@
<MenuItem Header="Window">
<MenuItem IsCheckable="True" Header="Ignore taskbar on maximize"
IsChecked="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Controls:MetroWindow}}, Path=IgnoreTaskbarOnMaximize}" />
<MenuItem IsCheckable="True" Header="Toggle FullScreen"
<MenuItem IsCheckable="True" Header="Toggle FullScreen (no taskbar, window style = none)"
IsChecked="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Controls:MetroWindow}}, Path=ToggleFullScreen}" />
</MenuItem>
</Menu>
@@ -49,19 +49,13 @@ private static void ToggleFullScreenPropertyChangedCallback(DependencyObject dep
{
metroWindow.UseNoneWindowStyle = true;
metroWindow.IgnoreTaskbarOnMaximize = true;
metroWindow.ShowMinButton = false;
metroWindow.ShowMaxRestoreButton = false;
metroWindow.ShowCloseButton = false;
metroWindow.WindowState = WindowState.Maximized;
}
else
{
metroWindow.UseNoneWindowStyle = false;
metroWindow.ShowTitleBar = true; // <-- this must be set to true
metroWindow.IgnoreTaskbarOnMaximize = false;
metroWindow.ShowMinButton = true;
metroWindow.ShowMaxRestoreButton = true;
metroWindow.ShowCloseButton = true;
metroWindow.WindowState = WindowState.Normal;
}
}

0 comments on commit c1d36f5

Please sign in to comment.