wpf扩展器头的右边宽度

时间:2016-04-25 12:38:05

标签: c# wpf width datatemplate expander

我发现了solution我的问题。

Width=”{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=x:Type Expander}}, Path=ActualWidth}”

但我的宽度不正确。 (不考虑切换按钮的宽度) XAML中有没有针对此的解决方案?

Result

<Page x:Class="Restore.Page1"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      xmlns:local="clr-namespace:Restore"
      mc:Ignorable="d" 
      d:DesignHeight="300" d:DesignWidth="300"
      Title="Page1">

    <Grid Background="AliceBlue" HorizontalAlignment="Stretch">


        <Expander Name="EXPANDER_NAME">
            <Expander.Header>
                <Grid Background="Red" Width="{Binding ElementName=EXPANDER_NAME, Path=ActualWidth}">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto"/>
                        <ColumnDefinition Width="30"/>
                    </Grid.ColumnDefinitions>
                    <TextBlock Text="sdfsfsd" Grid.Column="0" />
                    <Button Content="OK" Grid.Column="1" />
                </Grid>
            </Expander.Header>
        </Expander>

    </Grid>
</Page>

0 个答案:

没有答案