如何使WPF扩展控制切换按钮 [英] How to align WPF Expander control toggle button

查看:157
本文介绍了如何使WPF扩展控制切换按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我想知道是否有可能对准一个WPF扩展器控制,最右侧的切换按钮?

Hi I was wondering is it possible to align the toggle button on a WPF expander control to the far right side?

推荐答案

通过WPF所有的事情都是可能的。 ;)很不幸,不是所有的事情都很简单。这里最好的办法是重新模板的扩展。通过复制默认的扩展模板开始时,发现这里

With WPF all things are possible. ;) Unfortunately not all things are simple. Your best bet here is to re-template the expander. Start out by copying the default Expander template, found here.

接下来,找到电网包含2列,一个包含一个切换按钮和其他含内容presenter 。交换列,以便切换是在第一列然后改变列定义的尺寸所以第一列是明星般大小,第二是大小20.完成后,你应该有看起来像这样的模板的块:

Next, find the Grid that contains 2 columns, one containing a ToggleButton and the other containing a ContentPresenter. Swap the columns so the toggle is in column 1. Then change the column definition sizes so the first column is star-sized, and the second is size 20. When finished, you should have a chunk in the template that looks like this:

<Grid>
  <Grid.ColumnDefinitions>
    <ColumnDefinition Width="*" />
    <ColumnDefinition Width="20" />
  </Grid.ColumnDefinitions>
    <ToggleButton Grid.Column="1"
      IsChecked="{Binding Path=IsExpanded,Mode=TwoWay,
      RelativeSource={RelativeSource TemplatedParent}}"
      OverridesDefaultStyle="True" 
      Template="{StaticResource ExpanderToggleButton}" 
      Background="{StaticResource NormalBrush}" />
    <ContentPresenter Margin="4" 
      ContentSource="Header" 
      RecognizesAccessKey="True" />
</Grid>

继续修改模板,直到你得到的外观和感觉,你需要的。

Continue modifying the template until you get the look and feel that you need.

修改:MSDN上提供的模板是真正的扩展模板的裸机版本。如果你想在风格化扩展模板,使用前pression Blend和复制现有的控件模板的关闭扩展

EDIT: The template provided on MSDN is a bare-bones version of the "real" expander template. If you want the stylized expander template, use Expression Blend and copy the existing control template off an Expander.

这篇关于如何使WPF扩展控制切换按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆