wpf - 为什么这个扩展坞面板不起作用?

标签 wpf xaml

我有这个 xml:

 <DockPanel x:Name="TitleBar"  MouseDown="TitleBar_MouseDown" Background="Red">
        <Canvas DockPanel.Dock="Left">
            <Image Stretch="Fill" Width="295" Height="47" Source="/Resources\Images\TopPanel\Toplogo.png"/>
        </Canvas>
        <Canvas DockPanel.Dock="Right" Width="90">
            <Button Canvas.Left="70" DockPanel.Dock="Right" Width="16" Height="14" Style="{StaticResource TransparentButton}" Click="ButtonCloseWindowClick">
                <Image Height="14" VerticalAlignment="Top" >
                    <Image.Style>
                        <Style TargetType="{x:Type Image}">
                            <Setter Property="Source" Value="/Resources/Images/Toppanel/but_close.png"/>
                            <Style.Triggers>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter Property="Source"  Value="/Resources/Images/Toppanel/but_close_roll.png"/>
                                </Trigger>
                            </Style.Triggers>
                        </Style>
                    </Image.Style>
                </Image>
            </Button>
            <Image Canvas.Left="50" Stretch="Fill" Width="2" Height="33" Source="/Resources/Images/Toppanel/divider.png"/>
            <Button Canvas.Left="40" Width="16" Height="14" Style="{StaticResource TransparentButton}" Click="ButtonMinimizedClick" >
                <Image >
                    <Image.Style>
                        <Style TargetType="{x:Type Image}">
                            <Setter Property="Source" Value="/Resources/Images/Toppanel/but_minimise.png"/>
                            <Style.Triggers>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter Property="Source"  Value="/Resources/Images/TopPanel/but_minimise_roll.png"/>
                                </Trigger>
                            </Style.Triggers>
                        </Style>
                    </Image.Style>
                </Image>
            </Button>
            <Image  Canvas.Left="30"  Stretch="Fill" Width="2" Height="33" Source="/Resources/Images/Toppanel/divider.png"/>
            <Button   Canvas.Left="10" Canvas.Top="0"  Width="16" Height="14" Style="{StaticResource TransparentButton}" Click="ButtonInfoClick">
                <Image >
                    <Image.Style>
                        <Style TargetType="{x:Type Image}">
                            <Setter Property="Source" Value="/Resources/Images/Toppanel/but_info.png"/>
                            <Style.Triggers>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter Property="Source"  Value="/Resources/Images/TopPanel/but_info_roll.png"/>
                                </Trigger>
                            </Style.Triggers>
                        </Style>
                    </Image.Style>
                </Image>
            </Button>
            <Image  Canvas.Left="0" Canvas.Top="0"  Stretch="Fill" Width="2" Height="33" Source="/Resources/Images/Toppanel/divider.png"/>



        </Canvas>


    </DockPanel>

根据我的理解,第一个 Canvas 应显示在左侧,另一个 Canvas 应显示在窗口的右侧尺寸上,但两者都显示在左侧尺寸上。为什么停靠面板不起作用?

最佳答案

由于第二个 CanvasDockPanelLastChildFill 的最后一个子级。为 true(默认值):

If you set the LastChildFill property to true, which is the default setting, the last child element of a DockPanel always fills the remaining space, regardless of any other dock value that you set on the last child element.

针对 DockPanel 设置 LastChildFill="False"

<DockPanel x:Name="TitleBar" ... LastChildFill="False">

应该可以解决你的问题

关于wpf - 为什么这个扩展坞面板不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22512519/

相关文章:

wpf - 在 TextBox/RichTextBox 中 block 选择

c# - 如何在后面的代码中访问 C# Metro UI 中数据模板内的控件

C# Wpf 如何使用其中的按钮更改 Listviewitem 的高度?

c# - 为什么图像的流媒体源不起作用?

c# - Listview滚动触发Combobox SelectedValue并抛出异常

c# - 在绑定(bind)到 xaml 对象属性的属性 setter 中执行私有(private)函数是否合法?

c# - Windows Universal 10 中的饼图

c# - 将上下文菜单绑定(bind)到 View 模型属性

.net - 在 xaml 中为组合框设置选定值时出现问题

c# - MvvmLight EventToCommand 不再工作