我想做一个带有地铁风格的窗户。
我发现了以下三个图书馆:
http://elysium.asvishnyakov.com/en/
https://github.com/MahApps/MahApps.Metro
http://mui.codeplex.com/
所有这些都是针对.NET Framework 4+的。
有3.5的吗?
我还试着自己做(还没有完成-仍然需要设计它,并添加我不知道怎么做的调整),但我并不真的喜欢它是如何制作的……:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit" x:Class="Windows_Hider.MainWindow"
Title="Windows Hider" Height="350" Width="525" WindowStartupLocation="CenterScreen"
AllowsTransparency="True"
ResizeMode="CanResize" WindowStyle="None" BorderBrush="Black" BorderThickness="1" Icon="windowshider.ico">
<Grid>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Left" VerticalAlignment="Top">
<Image Width="24" Height="24" Source="{Binding Icon, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}"/>
<Label VerticalAlignment="Center" FontSize="14" Content="{Binding Title, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}"/>
</StackPanel>
<Grid MouseDown="Grid_MouseDown" Background="Transparent"/>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" VerticalAlignment="Top" Grid.Row="0">
<Button ToolTip="minimize" Background="White">
<Grid Width="30" Height="25">
<TextBlock Text="0" FontFamily="Marlett" FontSize="14" VerticalAlignment="Center" HorizontalAlignment="Center" Padding="3.5,0,0,3" />
</Grid>
</Button>
<Grid Margin="1,0,1,0">
<Button x:Name="Restore" ToolTip="restore" Visibility="Collapsed">
<Grid Width="30" Height="25" UseLayoutRounding="True">
<TextBlock Text="2" FontFamily="Marlett" FontSize="14" VerticalAlignment="Center" HorizontalAlignment="Center" Padding="2,0,0,1" />
</Grid>
</Button>
<Button x:Name="Maximize" ToolTip="maximize">
<Grid Width="31" Height="25">
<TextBlock Text="1" FontFamily="Marlett" FontSize="14" VerticalAlignment="Center" HorizontalAlignment="Center" Padding="2,0,0,1" />
</Grid>
</Button>
</Grid>
<Button x:Name="Close" ToolTip="close">
<Grid Width="30" Height="25">
<TextBlock Text="r" FontFamily="Marlett" FontSize="14" VerticalAlignment="Center" HorizontalAlignment="Center" Padding="0,0,0,1" />
</Grid>
</Button>
</StackPanel>
</Grid>
</Grid>
</Window>发布于 2013-10-19 10:12:00
好吧,这花了我几天的时间,但最终我还是做了些什么。
我不得不自己做,因为NetFramework3.5没有Metro窗口。
我合并了以下一些参考资料:
http://www.codeproject.com/Articles/107994/Taskbar-with-Window-Maximized-and-WindowState-to-N
http://blog.magnusmontin.net/2013/03/16/how-to-create-a-custom-window-in-wpf/
http://codekong.wordpress.com/2010/11/10/custom-window-style-and-accounting-for-the-taskbar/
http://blog.creativeitp.com/posts-and-articles/c-sharp/simple-methods-to-drag-and-resize-your-c-transparent-wpf-application-with-the-windowstyle-property-set-to-none/
这是最后的解决方案。
已知的问题/bug:
如果你能解决上面的任何问题,它会更好,但我对我所取得的成就感到满意。
编辑:
更新以允许调整大小模式(还添加了示例)
发布于 2013-10-12 17:40:36
很容易自己做这件事。您所需要做的就是复制您在Style UI中看到的Metro,就像您所说的那样。为了开始您的工作,下面是一个非常简单的Style,它更改Button元素的ControlTemplate以删除它们的默认外观:
<Style TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid>
<ContentPresenter HorizontalAlignment="Center"
VerticalAlignment="Center" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>当然,当用户将鼠标指针移动到Button上时,您会希望发生一些事情,您可以通过将VisualStateManager.VisualStateGroups添加到ControlTemplate来做到这一点。您可以在MSDN上的ControlTemplate类页面中找到这方面的完整示例。
其他控件Metro-style控件可以通过以同样的方式创建简单的ControlTemplate来轻松开发。基本上,您只需要删除默认的WPF外观,在大多数情况下,只需使用上面示例中的ContentPresenter或集合控件的ItemsPresenter来替换它。幸运的是,Metro的外观非常朴素和简单,只是记住要保持所有的间隔和简单。
要解决另一个问题,您需要调整大小;您可以将Window.ResizeMode属性设置为CanResizeWithGrip,以在Window的右下角添加调整大小的抓地力,就像在这些应用程序中经常看到的那样。
https://stackoverflow.com/questions/19335343
复制相似问题