将图标放在 WPF 扩展器控件的右端
您好,我尝试在设置复选框时在 WPF Expander 控件的右端放置一个绿色勾号图标。我当前的代码是:
<Expander x:Name="ImageExpander">
<Expander.Header>
<Grid Width="450">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Label Padding="0">My Header Text</Label>
<Image Grid.Column="1" Margin="0"
Source="C:\...\GreenTick.png" Width="18" />
</Grid>
</Expander.Header>
</Expander>
我使用网格将图标放在扩展器的右上角。这会将标题文本放置在旋转按钮旁边的通常位置,以展开扩展器。它还在靠近扩展器右端的位置进一步放置了 450 像素的图标。
我希望它不被硬编码,这样无论扩展器增长多宽,图标都会保持在右角。有人可以建议如何做到这一点吗?
我尝试将 Expander.header 的宽度绑定到 Expander 的宽度,但没有成功。
感谢您的任何建议!
Hi I am attempting to put a green tick icon at the right end of a WPF Expander control when a checkbox is set. My code currently is:
<Expander x:Name="ImageExpander">
<Expander.Header>
<Grid Width="450">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Label Padding="0">My Header Text</Label>
<Image Grid.Column="1" Margin="0"
Source="C:\...\GreenTick.png" Width="18" />
</Grid>
</Expander.Header>
</Expander>
I used a grid to put the icon in the top right corner of the expander. This puts the header text in the usual spot next to the twiddle for expanding the expander. It also puts an icon 450 pixels further along near to the right end of the expander.
I was hoping to have it not hard coded so that no matter how wide the expander grows the icon stays in the right corner. Can anybody advise how to do this?
I tried binding the width of the expander.header to the width of the expander with no luck.
Thanks for any advice!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是因为 Expander (ToggleButton ContentPresenter) 的默认模板。
这是修改后的模板,看看这就是你需要的结果
It is because of the Default Template of the Expander (ToggleButton ContentPresenter).
This is the modified template and see this is the result you required
您可以使用扩展器设置 32x32 图像
you can set 32x32 image with expander