I have a XamGrid inside an Expander with the XAML:
<Grid Grid.Column="2" Grid.Row="3" Grid.RowSpan="11" VerticalAlignment="Top" HorizontalAlignment="Left"> <Grid.RowDefinitions> <RowDefinition Height="Auto"/> <RowDefinition Height="30"/> <RowDefinition Height="20"/> <RowDefinition Height="*"/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> </Grid.ColumnDefinitions> <Expander HorizontalAlignment="Left" Grid.Row="0" VerticalAlignment="Top" IsExpanded="True" Style="{StaticResource DetailsExpanderStyle}" Margin="0,5,0,0" ><ig:XamGrid ItemsSource="{Binding GridViewModel.ItemsLoadedInGrid}" AutoGenerateColumns="False" BorderThickness="0" Margin="15,10,0,0" Background="Transparent" Height="250">
...
</Expander>
The Height was set to 'Auto' since it's within an expander. However, I always get a horizontal scrollviewer with a triangle as the image below:
https://ibb.co/dWB5D5
Is there a way to get rid of this? I tried to make the horizontalscrollviewer's visibility as collapsed or hidden but it does not work.
Hello Erika,
The XamGrid contains embedded ScrollBar, so you in order to hide it I can suggest several approaches here:
Approach 1:
You can insert the XamGrid inside a container of type Grid with Width equal to infinite, for example:
<Expander HorizontalAlignment="Left" Header="Details" > <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> </Grid.ColumnDefinitions> <ig:XamGrid x:Name="grdCurrentUser" Width="Auto" ItemsSource="{Binding}" > </ig:XamGrid> </Grid> </Expander>
Approach 2:
You can create a Style for ScrollBar and handle it's Loaded event by using EventSetter, this way in the event handler you can access the ScrollBar and check whether it is the ScrollBar you want to hide. Then you can set it's MinHeight and Height to 0, for example:
<Style TargetType="{x:Type ScrollBar}" > <EventSetter Event="Loaded" Handler="Scroll_Loaded"/> </Style>
private void Scroll_Loaded(object sender, RoutedEventArgs e){ if ((sender as ScrollBar).Name.ToString() == "HorizontalScrollBar") { (sender as ScrollBar).MinHeight = 0; (sender as ScrollBar).Height = 0; }}
Approach 3:
You can handle the SizeChanged event of XamGrid and by using the GetDescendantFromName method of our Utilities class you are able to access the embedded Scrollbar and set it's Visibility to Hidden.
I have attached a simple sample application. where you can test my suggestions.
Please let me know if you have any questions.
Sincerely,ZhivkoAssociate Software Developer
Thanks for your help. I did option 2 since I would need to limit the xamgrid size.
Also, option 3 did not work coz when I scroll vertically, the horizontal bar appears again.
Thank you for your feedback.
Let me know if you need from any further assistance on this.