2014-10-22 60 views
0

我想創建一個類似於用於在wpf中創建網站的導航欄。我想是這樣的: enter image description here使用按鈕創建導航欄wpf .net

我有這樣的代碼在XAML:

<Grid> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="auto" /> 
     </Grid.RowDefinitions> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="auto" /> 
      <ColumnDefinition Width="auto" /> 
      <ColumnDefinition Width="auto" /> 
      <ColumnDefinition Width="auto" /> 
      <ColumnDefinition Width="auto" /> 
      <ColumnDefinition Width="auto" /> 
      <ColumnDefinition Width="auto" /> 
     </Grid.ColumnDefinitions> 
     <Button Grid.Row="0" Grid.Column="0" Content="Companies" /> 
     <Button Grid.Row="0" Grid.Column="1" Content="Orders" /> 
     <Button Grid.Row="0" Grid.Column="2" Content="Employes" /> 
     <Button Grid.Row="0" Grid.Column="3" Content="Timesheets" /> 
     <Button Grid.Row="0" Grid.Column="4" Content="Payroll" /> 
     <Button Grid.Row="0" Grid.Column="5" Content="Billing" /> 
     <Button Grid.Row="0" Grid.Column="6" Content="Reports" /> 
    </Grid> 

,這是我的佈局: enter image description here

我該怎麼辦這個 「導航欄」?有可能創造出像這樣驚人的東西嗎?如果是的話我怎麼能做到這一點? 感謝

+0

我猜你需要一個'TabControl'和[自定義樣式(HTTP:// www.wpf-tutorial.com/tabcontrol/styling-the-tabitems/)。在...上下功夫。當你遇到特定問題時來到這裏。你的問題依然過於寬泛。 – 2014-10-22 11:03:20

回答

0

這應該工作,但它不是按鈕(造型的問題),它沒有箭頭位

Private Sub Load() Handles Me.Loaded 
    MenuReset() 
End Sub 
Private Sub MenuReset() Handles menu1.MouseLeave, menu2.MouseLeave, menu3.MouseLeave 
    Dim fore, back, border As New SolidColorBrush 
    fore.Color = Color.FromRgb(0, 0, 0) 
    back.Color = Color.FromArgb(0, 0, 0, 0) 
    border.Color = Color.FromArgb(0, 0, 0, 0) 
    menu1.Foreground = fore 
    menu1.Background = back 
    menu1.BorderBrush = border 
    menu2.Foreground = fore 
    menu2.Background = back 
    menu2.BorderBrush = border 
    menu3.Foreground = fore 
    menu3.Background = back 
    menu3.BorderBrush = border 
End Sub 
Private Sub MenuMouseMove(sender As Label, e As EventArgs) Handles menu1.MouseMove, menu2.MouseMove, menu3.MouseMove 
    Dim grad As New LinearGradientBrush 
    Dim fore, border As New SolidColorBrush 
    grad.StartPoint = New Point(0.5, 0) 
    grad.EndPoint = New Point(0.5, 1) 
    grad.GradientStops.Add(New GradientStop(Color.FromRgb(146, 179, 19), 0)) 
    grad.GradientStops.Add(New GradientStop(Color.FromRgb(116, 158, 9), 1)) 
    fore.Color = Color.FromRgb(255, 255, 255) 
    border.Color = Color.FromArgb(255, 0, 0, 0) 
    sender.Background = grad 
    sender.Foreground = fore 
    sender.BorderBrush = border 
End Sub 

<Grid Background="#ff86878a"> 
    <Grid x:Name="Menu" Margin="0" VerticalAlignment="Top" Height="30"> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="auto"/> 
      <ColumnDefinition Width="auto"/> 
      <ColumnDefinition Width="auto"/> 
      <ColumnDefinition Width="auto"/> 
     </Grid.ColumnDefinitions> 
     <Grid.Background> 
      <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> 
       <GradientStop Color="#FFC4C4C4" Offset="0.873"/> 
       <GradientStop Color="#FFDEDEDE"/> 
       <GradientStop Color="#FF9C9C9C" Offset="0.92"/> 
       <GradientStop Color="#FF626466" Offset="0.96"/> 
      </LinearGradientBrush> 
     </Grid.Background> 
     <Label x:Name="menu1" Grid.Column="0" Content="File" HorizontalAlignment="Left" Margin="0" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Padding="20,0,20,0" BorderBrush="Black" BorderThickness="0,0,0,3"> 
      <Label.Background> 
       <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> 
        <GradientStop Color="#FF92B312" Offset="0"/> 
        <GradientStop Color="#FF749E09" Offset="1"/> 
       </LinearGradientBrush> 
      </Label.Background> 
     </Label> 
     <Label x:Name="menu2" Grid.Column="1" Content="Gates" HorizontalAlignment="Left" Margin="0" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Padding="20,0,20,0" BorderBrush="Black" BorderThickness="0,0,0,3"> 
      <Label.Background> 
       <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> 
        <GradientStop Color="#FF92B312" Offset="0"/> 
        <GradientStop Color="#FF749E09" Offset="1"/> 
       </LinearGradientBrush> 
      </Label.Background> 
     </Label> 
     <Label x:Name="menu3" Grid.Column="2" Content="Flip Flops" HorizontalAlignment="Left" Margin="0" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" Padding="20,0,20,0" BorderBrush="Black" BorderThickness="0,0,0,3"> 
      <Label.Background> 
       <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"> 
        <GradientStop Color="#FF92B312" Offset="0"/> 
        <GradientStop Color="#FF749E09" Offset="1"/> 
       </LinearGradientBrush> 
      </Label.Background> 
     </Label> 
    </Grid> 

</Grid> 
+0

還有VB和WPF在同一個代碼框中 – RedLaser 2014-10-22 12:04:14

+0

我用的C#是一樣的嗎? – puti26 2014-10-22 13:23:34

+0

XAML與C#相同,但您需要首先調用變量類型,然後放置變量名稱...例如:「sender sender」作爲「sender as object」 – RedLaser 2014-10-22 15:40:32