WPF 创建侧边栏导航
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32397972/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WPF Create Sidebar Navigation
提问by Mr.Smithyyy
I am curious about how to create a sidebar navigation something like:
我很好奇如何创建侧边栏导航,例如:
I tried using an uniform grid but there ended up being too much spacing between "buttons" and I'm not sure if it's possible to modify the tab control to act like full width buttons instead of overhead tabs.
我尝试使用统一网格,但最终“按钮”之间的间距太大,我不确定是否可以修改选项卡控件以使其像全宽按钮而不是顶部选项卡。
Also if if its possible to add icons that would be a huge plus.
此外,如果可以添加图标,那将是一个巨大的优势。
回答by Baumi
You can make a Gridcolumn in your Standard grid with your wished Width. The into this Column you can put a stackpanel which fills your buttons from top to bottom.
您可以在您的标准网格中使用您希望的宽度制作一个 Gridcolumn。在此列中,您可以放置一个从上到下填充按钮的堆栈面板。
Like That:
像那样:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200"/>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0">
<Button Height="40">Test</Button>
<Button Height="40">Test2</Button>
</StackPanel>
</Grid>
It would look like this:
它看起来像这样:
If i missunderstod you please tell me and im gona edit it.
如果我missunderstod你请告诉我,我要去编辑它。
To add Images you can then create another grid in your Button with two columns: Like this:
要添加图像,您可以在 Button 中创建另一个包含两列的网格:像这样:
<Button>
<Grid Height="40" Width="200">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="40"/>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Image Grid.Column="0" Source="pack://siteoforigin:,,,/Resources/dll.png"></Image>
<TextBlock Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Center">Text</TextBlock>
</Grid>
</Button>
Note that you have to set your grid to Width="200" like you set your main Grid.Column because the Grid would not be the whole width of the button if you would not set it too 200.
请注意,您必须像设置主 Grid.Column 一样将网格设置为 Width="200",因为如果您不将其设置为 200,则 Grid 不会是按钮的整个宽度。


