Enable scroll bar inside text box wpf - wpf

I have a comments textbox put inside a groupbox, which occupies the whole bottom part of the screen.
I need to enable scroll bar both vertical and horizontal when the text exeeds the current size textbox .
But for me the textbox size is getting increased and scroll bar is enabled in the group box.
How shall i disable the scroll bar of the Group box and enable only the scroll bar inside textbox ?
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="{StaticResource FormWidthGridLength}" MaxWidth="{StaticResource FormColumnSpacerDouble}"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<!-- some controls here -->
<GroupBox Grid.Column="0" Grid.Row="3" Grid.ColumnSpan="4" Header ="Comments">
<TextBox Text="{Binding Comments}" TextWrapping="Wrap" />
</GroupBox>

Related

DataTemplate of Grid inside ListView is not resizing

I have a ListView that lays on top of UI graphics in my UserControl that I want to show and size using a Grid that matches the parent grid. I'm trying to template the way each item shown and sized using the ListView.ItemTemplate. The issue I'm having is that the DataTemplate is not sizing to the main Grid of the UI, and I'm not sure why.
This is what I've done, I think it a fairly simple and straight forward datatemplate:
<ListView ItemsSource="{Binding Path=StatusFilter}" Grid.Row="2" Grid.ColumnSpan="12">
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="92"/>
<ColumnDefinition Width="90"/>
<ColumnDefinition Width="85"/>
<ColumnDefinition Width="90*"/>
<ColumnDefinition Width="90*"/>
<ColumnDefinition Width="90*"/>
<ColumnDefinition Width="90*"/>
<ColumnDefinition Width="90*"/>
<ColumnDefinition Width="90*"/>
<ColumnDefinition Width="90*"/>
<ColumnDefinition Width="90*"/>
</Grid.ColumnDefinitions>
<Label Content="{Binding Path=ECNNumber}" Grid.Column="0"/>
<Label Content="{Binding Path=DateECNDue}" Grid.Column="1"/>
<Label Content="{Binding Path=Model.Model}" Grid.Column="2"/>
<--More stuff for each column-->
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
When this is displayed the grid is completely bypassed and each element is shown like a horizontally aligned stackpanel. To test that my DataTemplate wasn't faulty I threw it into an ItemsControl and it worked perfectly. It resized with the parent grid without any issues.
Why isn't this working for the ListView, and how do I get it to work? I need the selection and scrollview capability of the ListView otherwise I'd be using the ItemsControl.
I read something about Grid.SharedSizeScope but that doesn't work with dynamic sizing of grid, and that's all I could really find on this issue.

Auto Sizing between grid columns

I have two controls and a GridSplitter .
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<UserControlOne Grid.Colum="0" Visibility="{Binding MyProperty1}"/>
<GridSplitter Visibility="{Binding MyProperty1}" m:Splitterbehaviour.Apply= true/>
<UserControlTwo Grid.Colum="1" />
</Grid>
I am trying to show/hide the UserControlOne with the MyProperty1 which is working fine but when it is hidden i want the UsercontrolTwo to take whole page space. I could easily achieve this by using a stack or dock panel. But if i use the stackpanel or dockpanel my GridSplitter wont work.(I have a behaviour set to GridSplitter which will identify the first column and it will help to resize the first and second column)
I don't see how that splitter is working
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<UserControlOne Grid.Colum="0" Visibility="{Binding MyProperty1}"/>
<UserControlTwo Grid.Colum="1"/>
</Grid>

WPF, width of control change with window width change

In WPF application, a grid panel with 3 columns as defined below
<Grid.ColumnDefinitions>
<ColumnDefinition Width="250"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="250"/>
</Grid.ColumnDefinitions>
There is a slider in the second column,the width of the slider needs to reduce when the window width reduces and at some point the slider needs to disappear (kind of responsive design).
I tried naming the second column and binding width of slider to "ActualWidth" property of the column, but it didn't help.
There is another way to handle window's size change event and do some adjustments. Any other simple way?
Update 1 :
Adding more of my code
<Grid VerticalAlignment="Top" HorizontalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="250"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="250"/>
</Grid.ColumnDefinitions>
<!-- some other elements in cell 0-->
<StackPanel Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Center">
<Button Width="22" Height="22">
<Image Source="a.png"/>
</Button>
<Slider MinWidth="100" MaxWidth="320" Width="320"/>
<Button Width="22" Height="22" >
<Image Source="b.png"/>
</Button>
<!-- some other elements in cell 2-->
</StackPanel>
</Grid>
That's because the ActualWidth of a ColumnDefinition is not a DependencyProperty and ColumnDefinition doesn't notify when this property has changed.
Instead try grouping all your controls in column 2 inside a Grid and bind to the ActualWidth of the grid.
Assuming the slider is a generic WPF slider control, then simply placing the slider inside the second column should work, as by default the control should fill all available column space. Perhaps a style you have applied to the slider is affecting this functionality? The slider should fill up the column, and shrink down into nothingness as the window/column resizes if you use this code
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="250"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="250"/>
</Grid.ColumnDefinitions>
<Slider Grid.Column='1'></Slider>
</Grid>
EDIT:
Based on your new code, perhaps this might be more what you are after?
<DockPanel VerticalAlignment="Top">
<!-- Elements in cell 0-->
<Grid Width="250" DockPanel.Dock="Left"/>
<!-- Elements in cell 2-->
<Grid Width="250" DockPanel.Dock="Right"/>
<!-- Cell 1-->
<DockPanel>
<Button DockPanel.Dock="Left" Width="22" Height="22">
<Rectangle Fill="Blue"/>
</Button>
<Button DockPanel.Dock="Right" Width="22" Height="22" >
<Rectangle Fill="Blue"/>
</Button>
<Slider/>
</DockPanel>
</DockPanel>
The slider will resize and disappear accordingly, and the slider position will remain consistent during the resizing of the window

Wpf controls overlay?

I have Dockpanel on which there are two buttons (left and right sides) and a scrollviewer at the bottom. Is it possible to hide the left and right sides of this scrollviewer UNDER this buttons?
You could use a Grid instead of a DockPanel, either use the alignments or create columns and adjust the ColumnSpan, example of the latter:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition />
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<!-- Order matters, earlier controls are at the bottom unless you use Panel.ZIndex -->
<ScrollViewer Grid.Column="0" Grid.ColumnSpan="3"/>
<Button Grid.Column="0" Content="Left"/>
<Button Grid.Column="2" Content="Right"/>
</Grid>
(DockPanel is quite a poor control which can easily be replaced with a Grid in about every case)

Silverlight browse files control

I want to design a browse files control. Basically it is a textbox + button('...') + button ('upload')
Can I use a stackpanel for this? I want the two buttons to be on the right end of the panel. Upload button will be visible only if the textbox has text. The textbox should fill all the space.
Do you have an example hoe to put the first button('...') in the textbox itself?
Thanks a lot,
Radu
I would use a Grid instead. The StackPanel won't stretch the textbox.
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="70"/>
<ColumnDefinition/>
<ColumnDefinition Width="26"/>
<ColumnDefinition Width="60"/>
</Grid.ColumnDefinitions>
<TextBlock Text="File Path:" TextAlignment="Right" VerticalAlignment="Center" Margin="0 0 10 0"/>
<TextBox Name="txtFilePath" Grid.Column="1" Margin="2"></TextBox>
<Button Name="btnPrompt" Content="..." Grid.Column="2" Margin="2"></Button>
<Button Name="btnUpload" Content="Upload" Grid.Column="3" Margin="2"></Button>
</Grid>

Resources