C# 在调整窗口大小时,如何在StackPanel中放置滑块以增加其大小?
我目前正在使用WPF在C#中设置一个应用程序,并希望有一个包含几个按钮和滑块的水平StackPanel。调整窗口大小时,按钮不应更改其大小,而是滑块应填满空间: 在我的当前代码中,滑块没有宽度。它很薄。我试着用镶板的装订来确定宽度。我将滑块放入StackPanel的原因是,滑块本身不使用按钮旁边的其余大小。我的XAML代码如下所示:C# 在调整窗口大小时,如何在StackPanel中放置滑块以增加其大小?,c#,wpf,C#,Wpf,我目前正在使用WPF在C#中设置一个应用程序,并希望有一个包含几个按钮和滑块的水平StackPanel。调整窗口大小时,按钮不应更改其大小,而是滑块应填满空间: 在我的当前代码中,滑块没有宽度。它很薄。我试着用镶板的装订来确定宽度。我将滑块放入StackPanel的原因是,滑块本身不使用按钮旁边的其余大小。我的XAML代码如下所示: <StackPanel Name="controlPanel" Grid.Row="1" Grid.ColumnSpan="2" Orientation=
<StackPanel Name="controlPanel" Grid.Row="1" Grid.ColumnSpan="2" Orientation="Horizontal">
<StackPanel Name="buttonPanel" Orientation="Horizontal">
<Button x:Name="btnTlPl" Content="PL" Height="25" Width="25" BorderBrush="Green" BorderThickness="2" Margin="1"/>
<Button x:Name="btnTlSt" Content="ST" Height="25" Width="25" BorderBrush="Red" BorderThickness="2" Margin="1"/>
<Button x:Name="btnTlFw" Content="FW" Height="25" Width="25" BorderBrush="LightSalmon" BorderThickness="2" Margin="1"/>
<Button x:Name="btnTlBw" Content="BW" Height="25" Width="25" BorderBrush="LightSalmon" BorderThickness="2" Margin="1"/>
</StackPanel>
<StackPanel Name="sliderPanel" Orientation="Horizontal">
<Slider x:Name="sliderTopLeft" Margin="0,0,0,0"
Background="AliceBlue" Width="{Binding Path=ActualWidth, ElementName=sliderPanel}" Orientation="Horizontal" HorizontalAlignment="Right"
Value="0" Minimum="0" Maximum="19"
SmallChange="1" LargeChange="1"
TickPlacement="BottomRight" TickFrequency="1" IsSnapToTickEnabled="True" ValueChanged="sliderTopLeft_ValueChanged"/>
</StackPanel>
</StackPanel>
对我有什么建议吗?A
DockPanel
效果很好。还要确保删除滑块上的HorizontalAlignment=“Right”
<DockPanel
Name="controlPanel"
Grid.Row="1"
Grid.ColumnSpan="2"
LastChildFill="True">
<StackPanel
Name="buttonPanel"
DockPanel.Dock="Left"
Orientation="Horizontal">
<Button x:Name="btnTlPl"
Width="25"
Height="25"
Margin="1"
BorderBrush="Green"
BorderThickness="2"
Content="PL" />
<Button x:Name="btnTlSt"
Width="25"
Height="25"
Margin="1"
BorderBrush="Red"
BorderThickness="2"
Content="ST" />
<Button x:Name="btnTlFw"
Width="25"
Height="25"
Margin="1"
BorderBrush="LightSalmon"
BorderThickness="2"
Content="FW" />
<Button x:Name="btnTlBw"
Width="25"
Height="25"
Margin="1"
BorderBrush="LightSalmon"
BorderThickness="2"
Content="BW" />
</StackPanel>
<Slider x:Name="sliderTopLeft"
Margin="0,0,0,0"
Background="AliceBlue"
DockPanel.Dock="Left"
IsSnapToTickEnabled="True"
LargeChange="1"
Maximum="19"
Minimum="0"
Orientation="Horizontal"
SmallChange="1"
TickFrequency="1"
TickPlacement="BottomRight"
Value="0" />
</DockPanel>
如果网格有5列,前4列的宽度=自动,那该怎么办?