Reputation: 1759
I have a problem with the DockPanel
component. When i resize the panel I don't want the horizontal ScrollBar
to appear, but instead I want the left content to be resized also at the cost to lose some content. What I want to achieve in fact is that the right content of the DockPanel
is always visible, avoiding using the horizontal scrollbar to show it.
Hope i was clear!
This is the code: (this dataTemplate goes inside a listview)
<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:
I want the text higlighted to be trimmed instead of hide the expander arrow, that must be always to the right.
Thank you!
Upvotes: 0
Views: 1160
Reputation: 1759
Resolved! the trick is putting ScrollViewer.HorizontalScrollBarVisibility="Disabled"
in the listview's XAML definition
Upvotes: 0
Reputation: 2593
You should perhaps use a Grid instead of a DockPanel. A DockPanel is pretty much a quick grid, and you get much more freedom with a Grid.
I'd use four columns; auto, * auto, and auto, respectively. Then, to make sure the columns line up in the ListView, add the IsSharedSizeScope property. http://msdn.microsoft.com/en-us/library/system.windows.controls.grid.issharedsizescope.aspx
Because the second column's width is set to *, the grid will resize that instead of the columns with width set to auto. You could alternatively set the other columns to a set size.
Upvotes: 1