請我需要在wpf中創建六角形菜單作爲面板,但是我不知道如何創建面板爲六角形 注意我需要創建它而不是繪製它。 感謝如何創建使用WPF的六角形菜單?
1
A
回答
3
嘗試類似的東西:
<Window x:Class="HexagonMenu.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<Style x:Key="ButtonFocusVisual">
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate>
<Border>
<Rectangle
Margin="2"
StrokeThickness="1"
Stroke="#60000000"
StrokeDashArray="1 2"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<LinearGradientBrush x:Key="NormalBrush" StartPoint="0,0" EndPoint="0,1">
<GradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#FFF" Offset="0.0"/>
<GradientStop Color="#CCC" Offset="1.0"/>
</GradientStopCollection>
</GradientBrush.GradientStops>
</LinearGradientBrush>
<LinearGradientBrush x:Key="HorizontalNormalBrush" StartPoint="0,0" EndPoint="1,0">
<GradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#FFF" Offset="0.0"/>
<GradientStop Color="#CCC" Offset="1.0"/>
</GradientStopCollection>
</GradientBrush.GradientStops>
</LinearGradientBrush>
<LinearGradientBrush x:Key="LightBrush" StartPoint="0,0" EndPoint="0,1">
<GradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#FFF" Offset="0.0"/>
<GradientStop Color="#EEE" Offset="1.0"/>
</GradientStopCollection>
</GradientBrush.GradientStops>
</LinearGradientBrush>
<LinearGradientBrush x:Key="HorizontalLightBrush" StartPoint="0,0" EndPoint="1,0">
<GradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#FFF" Offset="0.0"/>
<GradientStop Color="#EEE" Offset="1.0"/>
</GradientStopCollection>
</GradientBrush.GradientStops>
</LinearGradientBrush>
<LinearGradientBrush x:Key="DarkBrush" StartPoint="0,0" EndPoint="0,1">
<GradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#FFF" Offset="0.0"/>
<GradientStop Color="#AAA" Offset="1.0"/>
</GradientStopCollection>
</GradientBrush.GradientStops>
</LinearGradientBrush>
<LinearGradientBrush x:Key="PressedBrush" StartPoint="0,0" EndPoint="0,1">
<GradientBrush.GradientStops>
<GradientStopCollection>
<GradientStop Color="#BBB" Offset="0.0"/>
<GradientStop Color="#EEE" Offset="0.1"/>
<GradientStop Color="#EEE" Offset="0.9"/>
<GradientStop Color="#FFF" Offset="1.0"/>
</GradientStopCollection>
</GradientBrush.GradientStops>
</LinearGradientBrush>
<SolidColorBrush x:Key="DisabledForegroundBrush" Color="#888" />
<SolidColorBrush x:Key="DisabledBackgroundBrush" Color="#EEE" />
<SolidColorBrush x:Key="WindowBackgroundBrush" Color="#FFF" />
<SolidColorBrush x:Key="SelectedBackgroundBrush" Color="#DDD" />
<Style TargetType="Button">
<Setter Property="SnapsToDevicePixels" Value="true"/>
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="FocusVisualStyle" Value="{StaticResource ButtonFocusVisual}"/>
<Setter Property="Height" Value="50"/>
<Setter Property="Width" Value="50"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid>
<Path x:Name="Hexagon" Stroke="Black" Stretch="Fill" Fill="{StaticResource NormalBrush}"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
Width="{TemplateBinding Width}" Height="{TemplateBinding Height}"
Data="M8.660254,0 L17.320508,5 17.320508,15 8.660254,20 0,15 0,5 8.660254,0 z"/>
<TextBlock Text="{Binding Path=Content, RelativeSource={RelativeSource Mode=TemplatedParent}}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter TargetName="Hexagon" Property="Fill" Value="{StaticResource DarkBrush}" />
</Trigger>
<Trigger Property="IsPressed" Value="true">
<Setter TargetName="Hexagon" Property="Fill" Value="{StaticResource PressedBrush}" />
</Trigger>
<Trigger Property="IsEnabled" Value="false">
<Setter TargetName="Hexagon" Property="Fill" Value="{StaticResource DisabledBackgroundBrush}" />
<Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<DockPanel>
<WrapPanel x:Name="MyHexagonMenu" DockPanel.Dock="Top">
<Button Content="File" />
<Button Content="Edit" />
<Button Content="About" />
<Button Content="Exit" />
</WrapPanel>
</DockPanel>
</Window>
+0
在此先感謝 – 2012-07-14 18:10:38
1
相關問題
- 1. 如何創建矩形背景的六角形?
- 2. 創建一個三維六角形圖
- 3. 在六角形網格中創建六角形按鈕的最佳方式
- 4. 如何創建徑向菜單在WPF
- 5. 如何設置使用Javascript和六角形瓷磚的六角形地圖?
- 6. 如何使用JavaFX創建三角形?
- 7. 如何使用AngularJS創建基於角色的動態菜單
- 8. 如何使用openGL在窗口左上角創建菜單
- 9. 如何在iPhone/iPad上創建六角形
- 10. 如何在famo.us中創建六角形自定義曲面
- 11. 如何爲Google地圖嵌入創建六角形iFrame?
- 12. 使用jQuery繪製六角形形狀
- 13. 如何使用css創建顏色全角圓角導航菜單
- 14. 如何使用JSF創建菜單欄和子菜單
- 15. 如何使用子菜單創建下拉菜單?
- 16. 如何使用子菜單創建浮動菜單
- 17. 如何使用MVC創建菜單/子菜單?
- 18. 如何創建Android應用一個圓形的中央菜單
- 19. 使用MvcSiteMapProvider創建菜單
- 20. 需要建議:如何使用C#(WPF/WinForms)創建全局菜單欄?
- 21. html中的六角形單元格
- 22. 如何用角度js創建響應菜單?
- 23. 如何在WPF中創建類似於Windows 7開始菜單的菜單
- 24. 在WPF中創建一個菜單欄?
- 25. WPF創建窗口彈出菜單
- 26. 繪製六角形使用Java錯誤
- 27. 如何創建與左側用WPF標籤的一個簡單的菜單?
- 28. 如何用Java中的子菜單創建彈出式菜單
- 29. WPF中上下文菜單的圓角矩形
- 30. 非空六邊形的六角中心
你有什麼試過?也許從[這個問題]開始(http://stackoverflow.com/questions/1443598/creating-grid-of-hexagons),看看你可以做什麼,一旦你創建六邊形控件? – 2012-07-14 17:31:29
不是這樣,它是談論繪圖我需要創建它作爲面板。 – 2012-07-14 17:41:08
你能解釋一下你想在六角形中控制嗎? – ethicallogics 2012-07-14 17:57:02