我的WPF用户控件必须永远不会比含按钮栏更宽

我已绑定在顶部的用户控件的宽度与ButtonGrid的宽度在顶部。

这不可行。 我希望我的用户始终是宽的ButtonGrid的宽度。 问题是加载的文件具有长名称> SUM(宽度的3个按钮),使用户控件一样宽的文档名称。 现在设想具有100个字符或更长的文件名和添加文件UserContol会磕碰和跳...

<UserControl x:Class="TBM.View.DocumentListView" 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:Behaviours="clr-namespace:FunctionalFun.UI.Behaviours" xmlns:Helper="clr-namespace:TBM.Helper" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300" Width="{Binding ElementName=ButtonGrid,Path=Width}" > <UserControl.Resources> <Helper:BooleanToVisibilityConverter x:Key="boolToVisibilityConverter" /> </UserControl.Resources> <Grid> <Grid.RowDefinitions> <RowDefinition Height="*" /> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <ListBox SelectionMode="Extended" VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Recycling" Behaviours:MultiSelectorBehaviours.SynchronizedSelectedItems="{Binding SelectedDocumentViewModelList,Mode=TwoWay}" Width="Auto" Focusable="True" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto" Grid.Row="0" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Name="documentListBox" BorderThickness="1" ItemsSource="{Binding DocumentList}" Visibility="{Binding ElementName=documentListBox,Path=HasItems, Converter={StaticResource boolToVisibilityConverter}}" > <ListBox.ItemTemplate> <DataTemplate> <StackPanel Orientation="Horizontal"> <!--<TextBlock Text="{Binding Path=Id}" />--> <TextBlock Text="{Binding Path=DocumentName}" /> </StackPanel> </DataTemplate> </ListBox.ItemTemplate> </ListBox> <UniformGrid x:Name="ButtonGrid" Grid.Row="1" Rows="1" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" > <Button Command="{Binding Path=DeleteDocumentCommand}" HorizontalAlignment="Stretch" Content="Delete" /> <Button Command="{Binding Path=AddDocumentCommand}" HorizontalAlignment="Stretch" Content="Add" /> <Button Command="{Binding Path=OpenDocumentCommand}" HorizontalAlignment="Stretch" Content="Open" /> </UniformGrid> </Grid> </UserControl>

--------------解决方案-------------

你也可以设置ParentGrid(包含控制)的宽度为固定大小,然后连接水平对齐到拉伸

尝试2东西

  1. 使用水平对齐方式对用户的控制伸展
  2. 设置绑定为maxWidth一样宽的结合
分类:WPF 时间:2015-03-15 人气:4
分享到:

相关文章

Copyright (C) 55228885.com, All Rights Reserved.

55228885 版权所有 京ICP备15002868号

processed in 0.830 (s). 10 q(s)