Drawing a Zune-like Control Bar in a WPF Application
Join the DZone community and get the full member experience.
Join For FreeSo you want to build Zune like applications? Here is the recipe for adjusting the necessary stuff borrowed from an excellent blog post over at bonus bits. First, create a new WPF application project and run it. You will get something like this:
Basic metroization
Now adjust the following properties for the window:
WindowStartupLocation="CenterScreen" WindowStyle="None" ResizeMode="NoResize" FontFamily="Segoe UI" Background="Transparent" AllowsTransparency="True"
Main design will consist of a Border element containing the main Gridelement. Here is the complete XAML:
<Border BorderBrush="White" BorderThickness=".5" Margin="10"> <Border.Effect> <DropShadowEffect BlurRadius="10" Color="#82000000" /> </Border.Effect> <Grid> <Grid.Background> <RadialGradientBrush> <GradientStop Color="#FF666666" Offset="0" /> <GradientStop Color="#FF444444" Offset=".6" /> <GradientStop Color="#FF444444" Offset="1" /> </RadialGradientBrush> </Grid.Background> <TextBlock Text="Hello Metro" Foreground="WhiteSmoke" Margin="20,12" FontSize="48"/> </Grid> </Border>
If you run the program now, here is what you should see:
This window is unmovable and cannot be resized. If you want any of that, consider the blog post mentioned above.
The control box
Standard control box buttons are drawn using the Marlett font where maximize/minimize/restore/close glyphs are stored. You can view them using the Character Map program accessible via the Start menu. Add the following XAML code inside the main Grid element:
<StackPanel Orientation="Horizontal" VerticalAlignment="Top" HorizontalAlignment="Right" Margin="4"> <StackPanel.Resources> <Style TargetType="TextBlock"> <Setter Property="Foreground" Value="White" /> <Setter Property="FontFamily" Value="Marlett" /> </Style> </StackPanel.Resources> <TextBlock Text="r" /> </StackPanel>
Character r is mapped to the close glyph in the Marlett font and the window should look like:
Add the rest of the desired glyphs as a separate TextBox elements. You can copy them directly from the Character Map or you can use. For the maximize button glyph you should use 1.
Change style as required, add hover effect, mouse click handlers and you are good to go. Happy designing.
Published at DZone with permission of Toni Petrina, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Trending
-
Reactive Programming
-
SRE vs. DevOps
-
5 Key Concepts for MQTT Broker in Sparkplug Specification
-
Chaining API Requests With API Gateway
Comments