[英]Click TextBlock to open Expander object WPF
I'm not so good at XAML, and I'm trying to make something like this: 我不太擅长XAML,并且我正在尝试制作以下内容:
(source: deviantart.net ) (来源: deviantart.net )
I want a few options (The orange ones) and then when I click the orange ones, they expand and show further options. 我需要一些选项(橙色选项),然后单击橙色选项时,它们会展开并显示更多选项。
Here's the little code I have: 这是我的小代码:
<ListView Background="#585858" Width="300" HorizontalAlignment="Left">
<ListViewItem>
<Grid Margin="15,5">
<TextBlock Foreground="#FFABADB3" Text="MenuTitle" FontSize="20" Grid.Row="0"/>
<Expander Grid.Row="1">
</Expander>
</Grid>
</ListViewItem>
</ListView>
But it doesn't really work as I want it to. 但这并不是我想要的那样真正起作用。 The Textblock and the Expander goes on the same line.
Textblock和Expander在同一行上。
Here's what my code looks like: 这是我的代码:
http://i.imgur.com/dbtNPUv.png http://i.imgur.com/dbtNPUv.png
If anyone can guide me in the right direction I'd be really glad! 如果有人能指导我正确的方向,我将非常高兴! Thanks in advance and happy holidays :)
在此先感谢您和节日快乐:)
Put the TextBlock in the Expander Header
将TextBlock放在Expander
Header
<ListView Background="#585858" Width="300" HorizontalAlignment="Left">
<ListViewItem>
<Grid Margin="15,5">
<Expander Grid.Row="1">
<Expander.Header>
<TextBlock Foreground="#FFABADB3" Text="MenuTitle" FontSize="20" Grid.Row="0"/>
</Expander.Header>
</Expander>
</Grid>
</ListViewItem>
</ListView>
But if you want the design from the picture,you will have a lot more work to do. 但是,如果您想从图片中进行设计,您将需要做更多的工作。 You will need to "retemplate" the
ListViewItem
and the Expander
. 您将需要“重新模板化”
ListViewItem
和Expander
。 Default templates are far from the one on the picture. 默认模板与图片上的模板相距甚远。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.