I have 3 datagrid that in a stackpanel and grid that I need to add in a scroll viewer too. When I try to add the scroll viewer to grid or stack panel nothing happens. When I surround the entire stackpanel and grid with a scroll viewer it works but it put the scroll bar to the side of the page separated from the datagrids. What I need is the grid/stackpanel to scroll all three grids together (I don’t want each data grid to scroll; I need them to stay grouped together). Below is my current code. Thank!!
<StackPanel Margin="10,162,0,50" HorizontalAlignment="Left" Width="365">
<Grid>
<Rectangle Fill="{StaticResource BaseColor}"
Stroke="Gray"
RadiusX="10"
RadiusY="10"
Margin="0,0,0,0" />
<StackPanel x:Name="IdentifyResultsStackPanel"
Margin="15,10,15,10"
Visibility="Collapsed">
<TextBlock Text="ELEMENTARY SCHOOL ATTENDANCE AREA:"
Foreground="White"
FontSize="14"
FontStyle="Italic"
Margin="0,0,0,5" />
<slData:DataGrid x:Name="IdentifyDetailsDataGrid"
AutoGenerateColumns="False"
LoadingRow="IdentifyDetailsDataGrid_LoadingRow"
HeadersVisibility="None" >
<slData:DataGrid.Columns>
<slData:DataGridTextColumn Binding="{Binding Path=Key}" FontWeight="Bold"/>
<slData:DataGridTextColumn Binding="{Binding Path=Value}"/>
</slData:DataGrid.Columns>
</slData:DataGrid>
<TextBlock Text="MIDDLE SCHOOL ATTENDANCE AREA:"
Foreground="White"
FontSize="14"
FontStyle="Italic"
Margin="0,0,0,5" />
<slData:DataGrid x:Name="IdentifyDetailsDataGrid2"
AutoGenerateColumns="False"
LoadingRow="IdentifyDetailsDataGrid_LoadingRow"
HeadersVisibility="None" >
<slData:DataGrid.Columns>
<slData:DataGridTextColumn Binding="{Binding Path=Key}" FontWeight="Bold"/>
<slData:DataGridTextColumn Binding="{Binding Path=Value}"/>
</slData:DataGrid.Columns>
</slData:DataGrid>
<TextBlock Text="HIGH SCHOOL ATTENDANCE AREA:"
Foreground="White"
FontSize="14"
FontStyle="Italic"
Margin="0,0,0,5" />
<slData:DataGrid x:Name="IdentifyDetailsDataGrid3"
AutoGenerateColumns="False"
LoadingRow="IdentifyDetailsDataGrid_LoadingRow"
HeadersVisibility="None" >
<slData:DataGrid.Columns>
<slData:DataGridTextColumn Binding="{Binding Path=Key}" FontWeight="Bold"/>
<slData:DataGridTextColumn Binding="{Binding Path=Value}"/>
</slData:DataGrid.Columns>
</slData:DataGrid>
</StackPanel>
</Grid>
</StackPanel>
The stackpanel was the issue. The following link helped me with the problem:
How to add a ScrollBar to a StackPanel in Silverlight?
Related
i want to change the data grid selected row color and height of the data grid columns in uwp xaml
i am using xamarin forms.
after installing the packages from NuGet. i am able to use the data grid. now problem is how to change the data grid column/row height and selected row color in uwp
my data grid xaml code : =
<controls:DataGrid AutoGenerateColumns="False" CanUserResizeColumns="False" IsReadOnly="True" Margin="31,21,103,483" Name="UserListView" VerticalScrollBarVisibility="Auto" UseLayoutRounding="True" HorizontalScrollBarVisibility="Auto" TabIndex="4" FontSize="14" Background="White"
HeadersVisibility="Column" SelectedIndex="0" HorizontalGridLinesBrush="#E1E1E1" IsTabStop="True" RenderTransformOrigin="0.504,0.739" Grid.Row="2" BorderBrush="#E1E1E1" BorderThickness="1" Grid.Column="2" Grid.ColumnSpan="7" >
<controls:DataGrid.Columns >
<controls:DataGridTemplateColumn CanUserReorder="False" CanUserResize="False" Width="50" x:Name="userCheckBox" >
<controls:DataGridTemplateColumn.CellTemplate >
<DataTemplate>
<CheckBox Foreground="#444444" Height="10" Width="10" Margin="15,10,0,10" x:Name="IndvCheckBox" DataContext="{Binding userId}" Unchecked="UserUnchecked" Checked="UserChecked" UseLayoutRounding="True">
</CheckBox>
</DataTemplate>
</controls:DataGridTemplateColumn.CellTemplate>
</controls:DataGridTemplateColumn>
<controls:DataGridTemplateColumn CanUserReorder="False" CanUserResize="False" Header="Name" Width="380" >
<controls:DataGridTemplateColumn.CellTemplate >
<DataTemplate>
<TextBlock Margin="10,20,0,10" x:Name="NameTextBox" Foreground="#444444" FontSize="12" FontFamily="Montserrat" >
<Run Text="{Binding userPrefix}" />
<Run Text="{Binding userFirstName}" />
<Run Text="{Binding userLastName}" />
</TextBlock>
</DataTemplate>
</controls:DataGridTemplateColumn.CellTemplate>
</controls:DataGridTemplateColumn>
<controls:DataGridTemplateColumn CanUserReorder="False" CanUserResize="False" Header="Email" Width="380" >
<controls:DataGridTemplateColumn.CellTemplate >
<DataTemplate>
<TextBlock Margin="10,20,0,10" Text="{Binding userEmail}" x:Name="NameTextBox" Foreground="#444444" FontSize="12" FontFamily="Montserrat" />
</DataTemplate>
</controls:DataGridTemplateColumn.CellTemplate>
</controls:DataGridTemplateColumn>
<controls:DataGridTemplateColumn CanUserReorder="False" CanUserResize="False" Header="Phone" Width="250" >
<controls:DataGridTemplateColumn.CellTemplate >
<DataTemplate>
<TextBlock FontSize="12" Margin="10,20,0,10" Text="{Binding userPhone}" Foreground="#444444" FontFamily="Montserrat"/>
</DataTemplate>
</controls:DataGridTemplateColumn.CellTemplate>
</controls:DataGridTemplateColumn>
<controls:DataGridTemplateColumn Tag="Col" Header="Update" Width="*">
<controls:DataGridTemplateColumn.CellTemplate >
<DataTemplate>
<Image HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,20,0,10" Height="15" DataContext="{Binding userId}" Width="15" Source="Images/Edit.png" Tapped="GridUpdateBtnClick" />
</DataTemplate>
</controls:DataGridTemplateColumn.CellTemplate>
</controls:DataGridTemplateColumn>
</controls:DataGrid.Columns>
</controls:DataGrid>
How to change the Datagrid selcted row color
There is ActiveRowColor property in DataGrid control that used to manage Row selected color. For more please refer this.
<dg:DataGrid ActiveRowColor="Red"/>
and data grid Header Font in UWP xaml
You could use the following code to manage the header font size.
<dg:DataGrid.HeaderFontSize>
<OnIdiom x:TypeArguments="x:Double">
<OnIdiom.Tablet>15</OnIdiom.Tablet>
<OnIdiom.Phone>12</OnIdiom.Phone>
</OnIdiom>
</dg:DataGrid.HeaderFontSize>
Unfortunately, DataGrid does not provide FontFamily property for Header. So you need set HeaderLabelStyle like the following.
<dg:DataGrid.HeaderLabelStyle>
<Style TargetType="Label">
<Setter Property="FontFamily" Value="SimSun"></Setter>
</Style>
</dg:DataGrid.HeaderLabelStyle>
The vertical Scrollbar is visible in W 8.1 but not in WP 8.1 on my emulator.
What have i missed?
I have also tried to set VerticalScrollBarVisibility to Visible
<Popup x:Name="LayerPopupWindow" IsLightDismissEnabled="True" >
<ListBox x:Name="MyList" Margin="3" Width="auto" Background="#DDFFFFFF"
Height="{Binding Path=ActualHeight,ElementName=MyMapView}" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollMode="Enabled">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Height="auto" >
<CheckBox IsChecked="{Binding IsVisible, Mode=TwoWay}" BorderBrush="Black" MinWidth="30"/>
<TextBlock Text="{Binding ID, Mode=OneWay}" VerticalAlignment="Center" >
<ToolTipService.ToolTip>
<StackPanel MaxWidth="400">
<TextBlock FontWeight="Bold" Text="{Binding CopyrightText}" TextWrapping="Wrap" />
<TextBlock Text="{Binding Description}" TextWrapping="Wrap" />
</StackPanel>
</ToolTipService.ToolTip>
</TextBlock>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Popup>
Looked at your links Depechie and tried it in my example, for some reason the scrollbars still wasnt visible.
Then i found this link
Making ScrollViewer's ScrollBar always visible through overriding or styling
Tried it and the scrollbars know were visible, so problem solved.
I have a StackPanel representing the top bar and a Hub representing books items. Both wrapped in the grid with two rows.
The problem is that in design mode hub content aligned properly to the top, just below my top bar. But in emulator it looks like all content aligned to the center of the hub.
In design time it looks like this:
But in emulator it looks like this:
Here is my XAML code:
<Page.Resources>
<DataTemplate x:Key="HubSectionHeaderTemplate">
<TextBlock Margin="0,0,0,-10" Text="{Binding}" FontSize="19" FontFamily="Open Sans" FontWeight="Light" FontStretch="ExtraExpanded" Foreground="#FF30323E">
<!--<TextBlock.RenderTransform>
<CompositeTransform/>
</TextBlock.RenderTransform>-->
</TextBlock>
</DataTemplate>
<!-- Grid-appropriate item template as seen in section 2 -->
<DataTemplate x:Key="Standard200x180TileItemTemplate">
<Grid Margin="0,0,15,15" Background="{ThemeResource ListViewItemPlaceholderBackgroundThemeBrush}" VerticalAlignment="Top">
<Image Source="{Binding ImagePath}" Stretch="UniformToFill" AutomationProperties.Name="{Binding Title}" Height="165" Width="115"/>
<!--<TextBlock Text="{Binding Title}" VerticalAlignment="Bottom" Margin="9.5,0,0,6.5" Style="{ThemeResource BaseTextBlockStyle}"/>-->
</Grid>
</DataTemplate>
</Page.Resources>
<Grid x:Name="LayoutRoot">
<Grid.RowDefinitions>
<RowDefinition Height="60"/>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Margin="0,-25,0,0">
<StackPanel.Background>
<ImageBrush ImageSource="Assets/CatalogTopBar.png" Stretch="UniformToFill"/>
</StackPanel.Background>
<Button x:Name="searchButton" Margin="0,25,-30,0" Height="15" Width="10" Content="" HorizontalAlignment="Right" VerticalAlignment="Center" BorderThickness="0" >
<Button.Background>
<ImageBrush ImageSource="Assets/noun_23695_cc.png" Stretch="Uniform"/>
</Button.Background>
</Button>
</StackPanel>
<Hub x:Name="Hub" x:Uid="Hub" Grid.Row="1" Background="White" Margin="0,25,0,0" VerticalContentAlignment="Top" VerticalAlignment="Top">
<HubSection x:Uid="HubSection2" Header="Популярные книги" Width="Auto"
DataContext="{Binding Groups[0]}" HeaderTemplate="{ThemeResource HubSectionHeaderTemplate}" >
<DataTemplate>
<GridView
Margin="0,-10,0,0"
ItemsSource="{Binding Items}"
AutomationProperties.AutomationId="ItemGridView"
AutomationProperties.Name="Items In Group"
ItemTemplate="{StaticResource Standard200x180TileItemTemplate}"
SelectionMode="None"
IsItemClickEnabled="True"
ItemClick="ItemView_ItemClick"
ContinuumNavigationTransitionInfo.ExitElementContainer="True">
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<ItemsWrapGrid />
</ItemsPanelTemplate>
</GridView.ItemsPanel>
</GridView>
</DataTemplate>
</HubSection>
</Hub>
</Grid>
</Page>
Ho-ho-ho... I finally managed to find the problem. After spending WEEKS!!! WEEKS, Carl! After spending few weeks I found out by accident that there is a MASSIVE "application name" <Hub.title> above my <Grid>.
It was not visible because of the white background and white font color of the text. By accidentally changing <RequestedTheme="Light"> I was finally able to see this text, because default font color changed to black. The text "application name" itself was not in my XAML source file, it was attached by localization facilities with x:Uid ="Hub" and corresponding value in resources.resw. After deleting x:Uid my layout returned to normal...
I have a LongListSelector control on a page in my Windows Phone 8 app. For this control I set a GroupHeaderTemplate and a ItemTemplate and both contain a TextBlock. If I align the TextBlock controls to center I have some weird behavior (maybe not weird but unexplainable to me at the moment). When I open the page on my phone the centered text moves ca. 5px to the right. The move is visible to the user (it's happening after the page is loaded). I tried to solve this problem but all margin changes (and other trials) did not change the behavior and my friend Google couldn't help me either. Can some explain to my why this is happening and how to solve this?
My code (simplified):
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="0">
<phone:LongListSelector x:Name="longList" LayoutMode="List" HideEmptyGroups ="true" Margin="5,0,5,5" ItemsSource="{Binding List, Mode=OneWay}" IsGroupingEnabled="True" Background="Transparent" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<phone:LongListSelector.Resources>
<DataTemplate x:Key="itemTemplate">
<Grid Margin="10,10,10,0" Background="#FFF3F1F1" HorizontalAlignment="Left">
<TextBlock x:Name="name" Margin="10" TextWrapping="NoWrap" Text="{Binding Name}" VerticalAlignment="Center" FontSize="40"/>
</Grid>
</DataTemplate>
<DataTemplate x:Key="groupHeaderTemplate">
<Grid Margin="10,10,10,0" Background="#FFF3F1F1" HorizontalAlignment="Center">
<TextBlock x:Name="name" Margin="10" TextWrapping="NoWrap" Text="test" VerticalAlignment="Center" FontSize="40"/>
</Grid>
</DataTemplate>
</phone:LongListSelector.Resources>
<!--<phone:LongListSelector.JumpListStyle>
<StaticResource ResourceKey="jumpListStyle"/>
</phone:LongListSelector.JumpListStyle>-->
<phone:LongListSelector.GroupHeaderTemplate>
<StaticResource ResourceKey="groupHeaderTemplate"/>
</phone:LongListSelector.GroupHeaderTemplate>
<phone:LongListSelector.ItemTemplate>
<StaticResource ResourceKey="itemTemplate"/>
</phone:LongListSelector.ItemTemplate>
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding SelectItemCommand}"
CommandParameter="{Binding SelectedItem, ElementName=longList}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</phone:LongListSelector>
</Grid>
Thanks in advance
I'm currently designing a windows 8 store app using XAML but I have a minor sizing issue. I have a ListView with a DataTemple.
The code for my ListView & DataTemplate are below:
<ListView x:Name="listPageItems"
Grid.Row="1"
SelectionMode="Extended"
IsSwipeEnabled="False"
ItemsSource="{Binding Mode=OneWay, Source={StaticResource items}}"
ItemTemplate="{StaticResource NavigationItemTemplate}"
ScrollViewer.VerticalScrollBarVisibility="Visible">
</ListView>
<DataTemplate x:Key="NavigationItemTemplate">
<Grid Height="75">
<Grid.RowDefinitions>
<RowDefinition Height="1.6*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Rectangle Fill="White" />
<Rectangle Fill="{StaticResource SSEGreenBrush}"
Grid.Row="1" />
<Border BorderThickness="2"
BorderBrush="{StaticResource SSEGreenBrush}"
Grid.RowSpan="2" />
<TextBlock x:Name="textTitle"
Text="{Binding ClientName}"
Style="{StaticResource TitleTextStyle}"
Foreground="{StaticResource SSEBlueBrush}"
Margin="10,5,5,5" />
<StackPanel Orientation="Horizontal"
Grid.Row="1"
HorizontalAlignment="Stretch">
<TextBlock Text="Last Edit :"
Style="{StaticResource SubtitleTextStyle}"
Foreground="{StaticResource SSEBlueBrush}"
Margin="3,0,0,3"
VerticalAlignment="Center" />
<TextBlock Text="SurveyDate"
Style="{StaticResource SubtitleTextStyle}"
Foreground="{StaticResource SSEBlueBrush}"
Margin="3,0,0,3"
VerticalAlignment="Center" />
</StackPanel>
</Grid>
</DataTemplate>
The listview is within a grid column with a fixed width of 240.
When the view is displayed the ListViewItems don't stretch to the width of the ListView. I've tried setting numerous properties including the HorizontalContentAlignment but I can't seem to get the ListViewItem to stretch!
Can anybody help?
I'm using Visual studio 2012, C# 4.5 and developing a Windows store app.
Try adding the following to your ListView definition
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListView.ItemContainerStyle>
The easiest thing to do is just adding HorizontalContentAlignment="Stretch" to the ListView. There normally is no need for anything more.