DockPanel上浆问题

时间:2012-01-02 09:40:38

标签: c# wpf dockpanel

我的DockPanel组件存在问题。当我调整面板大小时,我不希望出现水平ScrollBar,而是希望调整左侧内容的大小,但也会丢失一些内容。我想要实现的是DockPanel的正确内容始终可见,避免使用水平滚动条来显示它。 希望我很清楚! 这是代码:(此dataTemplate进入列表视图)

<DataTemplate DataType="{x:Type src:Voce}" x:Name="templateVoce">
        <StackPanel Name="stackPanelVoce" MaxWidth="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ActualWidth}">
                <DockPanel>
                    <TextBlock Name="labelCodiceVoce" ToolTip="{Binding Path=Voce.Voce}" Text="{Binding Path=Voce.Id}" Width="40" />
                    <TextBlock Name="labelDescrizioneVoce" ToolTip="{Binding Path=Voce.Voce}" Text="{Binding Path=Voce.Voce}" TextTrimming="CharacterEllipsis" Width="500" />
                    <TextBlock Name="labelDescrizioneNature" ToolTip="{Binding Path=Voce.Voce}" Text="{Binding Path=ListaNature, Converter={StaticResource listaNatureConverter}}"/>
                    <Expander Name="expander1" Expanded="expander1_Expanded" Collapsed="expander1_Collapsed" DockPanel.Dock="Right" Width="25" />
                    <TextBox Name="txtValoreVoce" PreviewKeyDown="txtValoreVoce_PreviewKeyDown" TabIndex="1" IsTabStop="False" GotFocus="txtValoreVoce_GotFocus" PreviewTextInput="txtValoreVoce_PreviewTextInput_1" AllowDrop="False" Loaded="txtValoreVoce_Loaded"  IsEnabled="{Binding Path=DataContext.VMPadre.IsModifica, RelativeSource={RelativeSource FindAncestor, AncestorType=src:InserimentoVoci, AncestorLevel=1}}" DockPanel.Dock="Right" Width="70" HorizontalAlignment="Right">
                        <TextBox.Style>
                            <Style>
                                <Setter Property="TextBox.Text" Value="{Binding Path=Valore, StringFormat=N0}" />
                                <Style.Triggers>
                                    <Trigger Property="TextBox.IsKeyboardFocusWithin" Value="True">
                                        <Setter Property="TextBox.Text" Value="{Binding Path=Valore, UpdateSourceTrigger=LostFocus, Mode=TwoWay}" />
                                    </Trigger>
                                </Style.Triggers>
                            </Style>
                        </TextBox.Style>
                        <TextBox.InputBindings>
                            <!--Disable Paste-->
                            <KeyBinding Command="ApplicationCommands.NotACommand"
                        Key="V"
                        Modifiers="Control" />
                        </TextBox.InputBindings>
                        <TextBox.ContextMenu>
                            <ContextMenu IsEnabled="False" Visibility="Hidden" />
                        </TextBox.ContextMenu>
                    </TextBox>
                    <TextBlock Name="lblPiuMeno" Margin="0,-5,0,0" VerticalAlignment="Center" FontSize="16" HorizontalAlignment="Right" DockPanel.Dock="Right" />
                    <Image Name="imgMulti" Source="/ClientConfidi;component/Immagini/112_Plus_Orange.ico" Margin="1" Visibility="Collapsed" ToolTip="La voce presenta nature opzionali" DockPanel.Dock="Right" HorizontalAlignment="Right" />
                    <Image Name="imgWarning" Source="/ClientConfidi;component/Immagini/Annotate_Warning.ico" Margin="1" Visibility="Collapsed" DockPanel.Dock="Right" HorizontalAlignment="Right" />
                </DockPanel>
                <ContentControl Name="controlExpander" IsEnabled="{Binding Path=DataContext.VMPadre.IsModifica, RelativeSource={RelativeSource FindAncestor, AncestorType=src:InserimentoVoci, AncestorLevel=1}}"/>
        </StackPanel>

在调整大小的临界点之前: before the critical point of resizing 在临界点之后:

after the critical point of resing 我希望修剪高亮显示的文本而不是隐藏扩展箭头,它必须始终在右边。 谢谢!

2 个答案:

答案 0 :(得分:1)

您应该使用Grid而不是DockPanel。 DockPanel几乎是一个快速的网格,你可以通过网格获得更多的自由。

我用四列;分别是auto,* auto和auto。 然后,要确保列在ListView中排列,请添加IsSharedSizeScope属性。 http://msdn.microsoft.com/en-us/library/system.windows.controls.grid.issharedsizescope.aspx

由于第二列的宽度设置为*,因此网格将调整其大小而不是宽度设置为auto的列。您也可以将其他列设置为设置大小。

答案 1 :(得分:0)

解决!诀窍是将ScrollViewer.HorizontalScrollBarVisibility="Disabled"放在listview的XAML定义